ajax - Calling .Net webservice with Jquery is causing woe when trying to post data -


data code to correct any data to send data key when done properly executed, ie data: "{ } "An empty JSON object and webservice does not take any parameters. I would like to post some data on the website, but I am getting worried.

When I try to set it in the data: "{'name': 'Niall', 'surname': 'Smith'}", I get an error

  { "message": "invalid web service call, the value for the parameter is missing: \ u0027json \ u0027.", "stacktrace" "system. Script.Services.WebServiceMethodData.CallMethod (target object on the web, IDictionary `2 parameters) \ r \ n System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams (target object, IDictionary`2 parameter) to \ r \ n System.Web on. Script.Services.RestHandler.InvokeMethod (HttpContext context, WebServiceMethodData MethodData, idictionary`2 rawParams) \ r \ nSystem.Web.Script.Services.RestHandler.Execu On teWebServiceCall (HttpContext context, WebServiceMethodData methodData) "," ExceptionType ":" System .InvalidOperationException "}  

is not supported web service.

This is my Jquery call to post on my data server.

  $ .ajeks ({type: "POST", Url: "/WebServices/BasketServices.asmx/AddItemToBasket", data: "{ 'Name': 'Niall'}", // Is it right? ContentType: "App / Jason; Charset = UTF-8", Dataprice: "Jason", Success: Onewood Adhesive}}; Function OnItemAddedSuccess (Results, eventArgs) {// JSON to make DSRAL and use it to update mini basket var response = JSON.parse (result.d); }  

Here's my WebService

  is [WebService (Namespace = "http://tempuri.org/")] [WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1) [System.ComponentModel.ToolboxItem] [System.Web.Script.Services.ScriptService] Public Square BasketServices: System.Web.Services.WebService {[WebMethod (true)) Public string AddItemToBasket (string json) { // do stuff myString.toJSON (); }}  

What could be the problem? Is this the format of JSON data to post? Could it be that I have not set the right features on my webserver, what kind of problems have been described?

Whatever I can think of, I have tried. Anyone have any ideas?

I think the webservice should be set to the parameter json . Try this AJAX call:

  var data = {'name': 'niall'}; $ .ajax ({type: "post", url: "/WebServices/BasketServices.asmx/AddItemToBasket", data: "json =" + JSON.stringify (data), contentType: "application / json; charset = utf-8 ", Datatype:" Jason ", success: onetime addance});  

Where JSON.stringify () is a method found in an "official" implementation:


Comments