web services - ASP.NET webservice responds with Internal Server Error (500) to post and get requests -
web services - ASP.NET webservice responds with Internal Server Error (500) to post and get requests -
the webservice code simple:
[webmethod] [scriptmethod(responseformat = responseformat.json)] public void receiveorder(string json) { context.response.write("ok"); }
and jquery calling webservice follows:
$.ajax({ type: "post", contenttype: "application/json; charset=utf-8", url: 'http://localhost:50730/gingerweb.asmx/receiveorder', data: 'test', //json.stringify(weborder), datatype: "text", success: function(data){ if(data === "ok") orderplaced(); } });
and yet chrome console reads in provocative red:
500 (internal server error)
the problem asmx web-service need find all input parameters in request. if @ to the lowest degree 1 input parameter not found in request server web service failed status code 500 (internal server error).
the reason send info in wrong way. name of input parameter of web method json
(see void receiveorder(string json)
). data
alternative of $.ajax
should in form
data: json.stringify({json: weborder})
if utilize type: "post"
instead of data: json.stringify(weborder)
tried before. in case in body of post request json=thevlue
instead of thevalue
.
if utilize type: "get"
format of data
parameter should changed to
data: {json: json.stringify(weborder)}
the value of datatype
should 'json'. after changes $.ajax
should work.
moreover recommend utilize relative paths in url
option. mean utilize '/gingerweb.asmx/receiveorder'
instead of 'http://localhost:50730/gingerweb.asmx/receiveorder'
. save same origin policy errors.
asp.net web-services jquery
Comments
Post a Comment