1

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/">&lt;div id=divContainer&gt;&lt;/h4&gt;Manager&nbsp;Name&lt;/div&gt;</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.

3
  • can you share your service code? Commented Nov 2, 2011 at 16:55
  • I would first recommend to check the actual data and its content type that your server is returning (using Fiddler or similar tools) Commented Nov 2, 2011 at 17:02
  • @Evgeny, well, i have included the response I am getting from the service here, thanks. Commented Nov 2, 2011 at 17:08

3 Answers 3

4

you can create a jQuery object from the response and read the text value from there to get the desired result.

$('#divManagers').append($(data).text());

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

Sign up to request clarification or add additional context in comments.

Comments

1

You need to set webResponse ContentType to: "text/html"

EDITED:

But anyway you can return JSON or XML and grab your data (XML using xpath, JSON just js object) and buid your div on the client site (you have better control on what you printing). Service should only provide plain data without any html stuff..

4 Comments

According to the link you provided there is!
HA! in the link that you posted, it does say html!
Sorry :) there is i'am just to tired :/
I am not using a page for webresponse?
0

Can you post the C# asmx code please?

You may have set the ContentType in the response like so:

HttpContext.Current.Response.ContentType = "text/html";

Or make sure you set the return type. For example, my service:

[WebService]
public class MySvc : WebService {

    [WebMethod (Description="Proxy for MyService")]
    public String Proxy()
    {return "<h1>MyHeader</h1>"}
}

More on SO w/ jQuery and ASMX:
Calling ASMX from jQuery

1 Comment

Hi, sorry but that did not really work, i am going throught the link you posted, thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.