jquery - [ScriptMethod(ResponseFormat = ResponseFormat.Json)] -


The above is not specified if the ASP.net web service is by default, what is the response format? In addition, if my web service is given below:

  [WebMethod ()] Public listing & lt; Sample & gt; Generate samples (string [] [] data) {ResultsFactory F = new result (data); & Lt; Sample & gt; Samples = f.GenerateSamples (); Return samples; }  

List of objects, if I change the JSON in the form of a response, then I have to change the return type to string, then how do I use the object in my javascript?

At the moment, I call this web service in my JS:

  $ .ajax ({type: "POST", url: "http: // localhost / TemplateWebService / Service Asmx / generatesSamples ", data: jsontext, contentType:" application / json; charset = utf-8 ", data type:" json ", success: function (response) {var sample = (typeof response.d) = = 'String'? Eval ('(' + response.d + ')'): reaction d; if (samples.length> gt; {doSomethingHere (samples);} else {warnings ("No sample generated Has been ");}}, error: function (xhr, position, error) {var msg = JSON.parse (xhr.responseText); alert (msg.Message);}});  

Though everything I've seen, even though everything works well, but the eval statement is never executed, which means that the web service always gives a string !

What is the [ScriptMethod (ResponseFormat = ResponseFormat.Json)] required for the web service definition side?

The way things are now, I can use the sample array and normally I can use each object and its property in any OOP code, which is very convenient, and everything No problem works, but I just wanted to make sure that I do not remember anything in my set up.

I am the basic element of the combination of jazzery jeeps with esp. Took not, and the response has not been mentioned - I read it on another site and I'm not sure how important it is. / P>

A list of 4 different changes on the asp.net web service side. I have only 2 - in my web.config, the service itself and the sample class have been implemented without any sorting, although it has properties too. I think the web service is JSON by default? And as long as your objects have the property, are they serialized by default? Until I read this article, I did not understand.

Response format is not required Only four things are needed to include both client and server settings :

  • Your web Add ScriptHandlerFactory HttpHandler to the config.
  • With your web service [ScriptService] attribute
  • Request service methods with post verb.
  • Request service methods with a content type of "application / json".

When you do those four things, the responses to service methods will be automatically sorted as JSON.


Comments