javascript - In JQuery why one of ajax request is working while other isn't? -
i developing application in have call multiple ajax requests. sending $.get , $.post ajax requests working fine tried give shot common $.ajax request.the problem $.ajax not working, below piece of code
//get request $.get works $.get("/requestcont/task2", function (data) { alert(data); }); //common ajax request below don't work $.ajax({ url: "/requestcont/task2", type: "get", datatype: "json", success:function(data) { //processing json data here }, failure:function(data) { //handling error here } });
i using asp.net mvc , actual code haven't wrote here piece of code demonstrate works or not. action in controller requestcont
public actionresult task2() { if (request.isajaxrequest()) { return json(new { msg = "data retrieved" }); } else { return null; } }
any thoughts on that. want retrieve json data !. doing wrong or ? 1 me out !. !!.
you sending json data in wrong format backend.
important: of jquery 1.4, if json file contains syntax error, request fail silently. avoid frequent hand-editing of json data reason. json data-interchange format syntax rules stricter of javascript's object literal notation. example, strings represented in json, whether properties or values, must enclosed in double-quotes. details on json format, see http://json.org/.
source:
check similar question
jquery $.ajax request of datatype json not retrieve data php script
Comments
Post a Comment