Skip to content

Instantly share code, notes, and snippets.

@backy22
Created February 26, 2015 15:16
Show Gist options
  • Save backy22/e0b5c5baf3aeee51efb0 to your computer and use it in GitHub Desktop.
Save backy22/e0b5c5baf3aeee51efb0 to your computer and use it in GitHub Desktop.
$(function() {
var house = {
"dan1": "根津",
"dan2": "渋谷",
"dan3": "外苑前",
"dan4": "神楽坂"
};
// 表示するフォームは 'dialog-form' という ID で定義します。
$("#dialog-form1").dialog({
autoOpen: false,
height: 350,
width: 450,
modal: true,
buttons: { // ダイアログに表示するボタンと処理
"送信": function() {
var $form1=$(this).find('form'); 
$.ajax({
url: $form1.attr('action'),
type: $form1.attr('method'),
data: $form1.serialize(),
success:function(result, textStatus, xhr){
$form1[0].reset();
alert("送信しました");
$("#dialog-form1").dialog("close");
}
});
},
"閉じる": function() {
$(this).dialog("close");
},
},
});
// 「開く」ボタンがクリックされたらダイアログを表示
$(".open1").click(function() {
$("#dialog-form1").dialog("open");
$.ajax({
url: "/guestget.php?userhouse="+userhouse,
type: "GET",
success:function(result, textStatus, xhr){
var returnArray = JSON.parse(result);
$("#guestname").val(returnArray["guestname"]);
$("#people").val(returnArray["people"]);
$("#stay1").val(returnArray["stay1"]);
$("#stay2").val(returnArray["stay2"]);
 }
 });
var dan = $(this).data("dan");
switch (dan){
case "dan1":
$("#userhouse1").val(house["dan1"]);
break;
case "dan2":
$("#userhouse1").val(house["dan2"]);
break;
case "dan3":
$("#userhouse1").val(house["dan3"]);
break;
case "dan4":
$("#userhouse1").val(house["dan4"]);
break;
}
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment