Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The answer is very easy and based on my previous posts <a href="https://stackoverflow.com/questions/2670147/can-i-return-json-from-an-asmx-web-service-if-the-contenttype-is-not-json/2671583#2671583">Can I return JSON from an .asmx Web Service if the ContentType is not JSON?</a> and <a href="https://stackoverflow.com/questions/2651091/jquery-ajax-call-to-httpget-webmethod-c-not-working/2656543#2656543">JQuery ajax call to httpget webmethod (c#) not working</a>.</p> <p>The data should be JSON-encoded. You should separate encode every input parameter. Because you have only one parameter you should do like following:</p> <p>first construct you data as native JavaScript data like:</p> <pre><code>var myData = {Address: {Address1:"address data 1", Address2:"address data 2", City: "Bonn", State: "NRW", Zip: "53353", {Code: 123, Description: "bla bla"}}}; </code></pre> <p>then give as a parameter of ajax request <code>{request:$.toJSON(myData)}</code></p> <pre><code>$.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "http://bmccorm-xp/HBUpsAddressValidation/AddressValidation.asmx/ValidateAddress", data: {request:$.toJSON(myData)}, dataType: "json", success: function(response){ alert(response); } }) </code></pre> <p>instead of $.toJSON which come from the JSON plugin you can use another version (JSON.stringify) from <a href="http://www.json.org/" rel="nofollow noreferrer">http://www.json.org/</a></p> <p>If your WebMethod had parameters like</p> <pre><code>public Response ValidateAddress(Request request1, Request myRequest2) </code></pre> <p>the value of <code>data</code> parameter of the <code>ajax</code> call should be like</p> <pre><code>data: {request1:$.toJSON(myData1), myRequest2:$.toJSON(myData2)} </code></pre> <p>or</p> <pre><code>data: {request1:JSON.stringify(myData1), myRequest2:JSON.stringify(myData2)} </code></pre> <p>if you prefer another version of JSON encoder.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload