Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3635936
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:58:02+00:00 2026-05-19T00:58:02+00:00

I am trying to create an ajax request to a WebService that returns data

  • 0

I am trying to create an ajax request to a WebService that returns data given some specified parameters in XML. This seems to work well in IE, but Firefox can’t decode the response. I can view the response successfully in Fiddler after decoding also. Here is the code:

$(function() {
    $.ajax({
        type: "GET",
        url: 'http:/localhost/webservice.asmx/GetTags?groupId=10',
        contentType: "text/xml; charset=utf-8",
        dataType: "xml",
        success: function(response) {
            $('#result').html('success',response);
            $(response).find("string").each(function() {
                $('#result').append($(this).text());
            });
        },
        error: function(response) {
            $('#result').html('failure',response);
        }
    });

});

Is there a way to specify that response needs to be decoded? Or any other way to make it work?

EDIT:
@Nikki9696 – it’s not JSON encoded as the data is returned in XML.

@Oleg – The sample XML I can see in the browser if accessing webservice via a URL is as follows:

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
  <string>tag 1</string>
  <string>tag 2</string>
  <string>tag 3</string>
</ArrayOfString>

The fiddler in TextView returns � and a message

“Response is encoded and may need to
be decoded before inspection. Click
here to transform.”

Once clicked it displays the same XML. I turn off dynamic content compression in the IIS then the XML is visible in fiddler straight away, but FF still can’t cope, so that rules out compression.

I played around with the script a little bit, seems like jQuery can default to or guess some parameters, so dataType, for example, is not compulsory. With these settings I get a success message, however it still doesn’t know what to do with the data. I tried setting dataType to “jsonp” as suggested in some SS thread (can’t find it at the moment, will link it when I do) and the error changes to missing ; before statement, I guess because it’s not JSON object, but XML. Is there a way to set webservice to return a JSON instead?

EDIT 2: I’ve updated url to reflect what actually happened. Sorry I missed it out, made it impossible for anyone to spot it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:58:03+00:00Added an answer on May 19, 2026 at 12:58 am

    Because you use relative URL like '/webservice.asmx/GetTags?groupId=10' you had no problem with different domain. It seems to me that you should just fix a litle your JavaScript code. For example the following code

    $(function () {
        $.ajax({
            type: "GET",
            url: '/WebService1.asmx/GetTags',
            contentType: "text/xml; charset=utf-8",
            data: {groupId:10},
            success: function (response) {
                $('#result').html('success:');
                $(response).find("string").each(function () {
                    $('#result').append('<br />'+$(this).text());
                });
            },
            error: function (response) {
                $('#result').html('failure:<br />' + response.responseText);
            }
        });
    });
    

    works fine in Internet Explorer, Firefox and Google Chrome. If you need I could post the URL where you could download the whole working Visual Studio 2010 project.

    UPDATED: To return JSON instead of XML from the web method you can replace [ScriptMethod(UseHttpGet = true)] to the [ScriptMethod (UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] attribute (in .NET 4.0 you can do the same in different other ways) and modify JavaScript code to the following

    $(function () {
        $.ajax({
            type: "GET",
            url: '/WebService1.asmx/GetTagsJson',
            contentType: "application/json; charset=utf-8",
            data: { groupId: 10 },
            //dataType: "xml",
            success: function (response) {
                $('#result').html('success:');
                $(response.d).each(function () {
                    $('#result').append('<br />' + this);
                });
            },
            error: function (response) {
                $('#result').html('failure:<br />' + response.responseText);
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a bookmarklet that will start off an AJAX call to
Trying to create a list to return some JSON data to a view. Following
I am trying create a WCF service that leverages the WPF MediaPlayer on the
Trying to create my first iPhone app that would play back audio. When I
Trying to create a small monitor application that displays current internet usage as percentage
I'm trying to create a sitemap using Linq to Xml, but am getting an
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
Trying to create a user account in a test. But getting a Object reference
Trying to create several layers of folders at once C:\pie\applepie\recipies\ without using several different
I'm trying to create a bookmarklet for posting del.icio.us bookmarks to a separate account.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.