jquery - JS Fiddle JSON/ECHO returning empty object -
i learning ajax, jquery , json.
i have following js fiddle sending request json/echo , response empty object. can tell me doing wrong?
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>"); }
in order jsfiddle echo
ajax working have send data string. in addition path /echo/json/
post key json
, string value
change
var data = getpersondetails();
to
var data = {json: json.stringify(getpersondetails())};
if working html be:
var data ={ html:'<p>some text</p>'};
and path /echo/html/
Comments
Post a Comment