javascript - why does returning the jquery AJAX promise in this function fail to give me the data? -
this ajax works on jsfiddle
var = $.ajax({ url: "/echo/json/", type: "post", data: { json: json.stringify({ a: true }) }, datatype: "json" }); a.done(function (data) { console.log(data); }); why won't work when make a function , return ajax promise?
var = function () { return $.ajax({ url: "/echo/json/", type: "post", data: { json: json.stringify({ a: true }) }, datatype: "json" }); } a.done(function (data) { console.log(data); }); is not correct syntax? well, apparently not, how can build ajax request function? fiddle
since a function, have call it:
a().done(function(data) { console.log(data); });
Comments
Post a Comment