Jakub
Jakub

Reputation: 20475

Odd <string></string> response returned by .NET webservice for ajax call

I'm new to ASP.NET and working with one of our inhouse devs, but they are out at the moment, I have a webservice to consume, but I am getting a result I haven't seen before:

data comes back like this:

<string xmlns="https://domain.com">
"<option>asdas</option><option>asdas</option><option>asdas</option>
 <option>asdas</option><option>asdas</option><option>asdas</option>"
</string>

I have access to the .NET as well and I see the following:

[WebMethod(true)]
public string GetProductTypesByProductLine(string productLine, int cono)
{
    var results = service.GetProductTypes(productLine, cono);
    StringBuilder sb = new StringBuilder(1000);
    foreach (var result in results)
    {
        sb.Append(string.Format("<option value='{0}'>{1}</option>", result, result));
    }

    return sb.ToString();
}

Can someone point me in the right direction? I'm just expecting a quick simple HTML output so I can utilize if to a jQuery html ajax call.

Upvotes: 0

Views: 243

Answers (2)

DaveB
DaveB

Reputation: 9530

Since you are expecting a string to be returned, use a HTTP handler instead. A web service will package it's response as either XML or JSON. See How To Create an ASP.NET HTTP Handler by Using Visual C# .NET to get you started.

You can then use the jQuery .load() function to get the text into your HTML element.

Upvotes: 1

Icarus
Icarus

Reputation: 63956

Check that you are calling your webmethod as follows:

$.ajax({
      "type": "POST",
       "dataType": 'json',
       "contentType": "application/json; charset=utf-8",
        //etc
 });

Upvotes: 0

Related Questions