I have a web service which adds an item to the database after being called using JQuery Ajax. The web service returns a string, and I can't manage to pick up only the string part returned. Instead I receive {"d":"The message I want to display"} using alert(data);.
I also tried alert(Object.keys(JSON.parse(data))[0]); which returns d and alert(Object.keys(JSON.parse(data))[1]); or alert(data.d); returns Undefined.Here's what my code looks like
function AddAjaxJQuery() {
var isbn = $('#<%= txtIsbn.ClientID %>').val();
var pdata = { "book": { "Isbn": isbn} };
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/BookWebService.asmx/InsertBook",
data: JSON.stringify(pdata),
dataType: 'text',
async: true,
success: function (data, textStatus) {
alert(data);
},
error: function (error) {
alert(data);
}
});
}