Currently I have a button that with jQuery/AJAX searches for all customers from a SharePoint list and my web service return an XML string. I then populate a dropdown with data from the XML.
I know wanted to pass on a parameter (customer name) for a search function and I can return what I want from the SharePoint list but my AJAX call returns error (parseerror).
To get all customers (which works):
$.ajax({
type: "GET",
url: "SynchroniseCustomers.asmx/GetAllCustomers",
dataType: "text/xml",
error: function (xhr, status) {
hideLoading();
},
beforeSend: function () {
showLoading("customers");
},
success: function (xml) {
hideLoading();
populatecustomerDropdownList($(xml).text());
}
});
I am not sure on how to go on about this but I tried
var customer = CustomerName;
$.ajax({
type: "GET",
data: { CustomerName: JSON.stringify(customer) },
url: "SynchroniseCustomers.asmx/GetCustomerByName",
dataType: "json",
error: function (xhr, status) {
hideLoading();
alert(xhr + " " + status);
},
beforeSend: function () {
showLoading("Customers");
},
success: function (xml) {
hideLoading();
populateCustomerDropdownList($(xml).text());
}
});
Can someone please point me in the right direction on how to perform this?
Thanks in advance.
Your specificing your return data type as JSON, it should be XML:
Also this looks wrong:
When you do
$(xml)you access your structure just like HTML, so for example if the structure is:jQuery: