0
我正在學習ajax,jquery和json。JS小提琴JSON/ECHO返回空對象
我有以下JS提琴發送請求到JSON/ECHO和響應是一個空對象。誰能告訴我我做錯了什麼?
http://jsfiddle.net/deandalby/7a2t0eb5/3/
var saveUrl = "http://fiddle.jshell.net/echo/json/";
$(document).ready(function() {
$("#saveButton").click(function() {
Save();
});
});
function GetPersonDetails() {
var arrayx = $(":input").serializeArray();
var json = {};
jQuery.each(arrayx, function() {
json[this.name] = this.value;
});
writeToDom('Formatted JSON', JSON.stringify(json, null, 4));
return json;
}
function Save() {
var data = GetPersonDetails();
$.ajax({
url: saveUrl,
dataType: "JSON",
data: data,
type: "POST",
cache: false,
success: function (response) {
writeToDom('Plain Response', JSON.stringify(response));
writeToDom('Formatted Response', JSON.stringify(response, null, 4));
},
error: function (response) {
alert("error");
},
complete: function() {
writeToDom("complete", "");
}
});
}
function writeToDom(title, content) {
$("form").append("<div class='alert alert-success' role='alert'>" + title + ":</div><div><pre>" + content + "</pre></div>");
}