I have a jquery block that does some ajax stuff like this:
$.ajax({
url: '/webservices/manager.asmx/addNew',
type: "POST",
dataType: "html",
data: { id: Id, name: Name, dept: Dept, helpId: HelpId },
success: function (data) {
//append to the table
$('#divManagers').append(data);
},
error: function () {
//console.log('error');
}
});
So it passes through just fine, asmx receives the data and I calculate stuff, then finally I respond with something similar to this:
<div id="divContainer">
<h2>Manager Name</h2>
</div>
Now, even though I have my dataType set to html I get my response encased in an xml string:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/"><div id=divContainer></h4>Manager Name</div></string>
and they all actually just gets appended to the page, the complete text, without rendering as actual html elements.
What is going on please?
EDIT
I am just constructing the html in my asmx. something like
StringBuilder component = new StringBuilder();
component.appendFormat("<div id='divComponent'><h2>{0}</h2></div>', managerDataRow["ManagerName"].ToString());
return component.ToString();
My asmx is a seperate, proper asmx page, not a [webmethod] method inside a normal aspx page. Thanks.
if there are any difference between my actual output and returned result here it is because I edited it to make it short. thanks.
you can create a jQuery object from the response and read the
textvalue from there to get the desired result.Also this post might answer why you don’t get back straight HTML in the response
How to get clean/pure HTML from ASMX web service call