Building a JSON Object for AJAX WebService Communication
To construct a properly formatted JSON object for an AJAX WebService, follow these steps:
1. Create the Data Object:
var myData = { Address: { Address1: "123 Main Street", Address2: null, City: "New York", State: "NY", Zip: "10000", AddressClassification: null } };
2. JSON-encode the Data:
var encodedData = $.toJSON(myData);
var encodedData = JSON.stringify(myData);
3. Send the Data in AJAX Request:
$.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "http://bmccorm-xp/HBUpsAddressValidation/AddressValidation.asmx/ValidateAddress", data: { request: encodedData }, dataType: "json", success: function(response) { alert(response); } });
Note:
The above is the detailed content of How to Properly Structure JSON Data for AJAX Web Service Communication?. For more information, please follow other related articles on the PHP Chinese website!