jquery - How to frame AJAX request -
i need call wcf service webpage. method in service uses generic list argument,i need know how frame ajax query?
method:
public list<filelistentity> listlogfiles(string status, list<filelistentity> filelist) { .............//implementation.... return filelist; }
1st time when method called 'filelist' passed null, method populates list , send website. 2nd time website sends received filelist along status service.
ajax query:
var status = definestatus(); var value; var jsonobj; function calllogservice(){ debugger; if (value == null) { jsonobj = "null"; } else { jsonobj=value; } $.ajax({ type: "post", url: "http://localhost:56256/searchservice.svc/listlogfiles", data: '{"status":"'+ status+'","filelist":'+jsonobj+' }', crossdomain: true, contenttype: "application/json; charset=utf-8", datatype: "json", processdata: true, success: function (response) { value = response; display(value); debugger; alert("success"); //debugger; }, error: function () { alert("an error has occured, please try refreshing !"); } }); }
this works 1st time when jsonobj null doesn't works second time when jsonobj contains value. says:
failed load resource: server responded status of 500 (internal server error)
i think argument not passed correctly during second time. idea? how resolve.
finally found answer, data i'm sending service wrong. 1st change
if (value == null) { jsonobj = "null"; } else { jsonobj=value.d; }
value.d(or value.data in case, check using debugger) contains actual data.
2nd change, inside ajax query write:
data: json.stringify({ status: status, filelist: jsonobj })
instead of data: '{"status":"'+ status+'","filelist":'+jsonobj+' }',
Comments
Post a Comment