Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery AJAX & an ASP.NET web service works locally but not remotely

Tags:

jquery

asp.net

Interesting one here. I have an ASP.NET 1.1 project that contains a web service in it. I'm using jQuery's AJAX functionality to call some services from the client. This is what my code looks like:

$.ajax({
    type: "POST",
    url: 'foo.asmx/functionName',
    data: 'foo1=' + foo1 + '&foo2=' + foo2,
    dataType: "xml",
    success: function(xml) {
        //do something with my xml data
    },
    error: function(request, error){
        //handle my error

    }       

});

This works great when I run the site from my IDE on localhost. However, when I deploy this site to any other server I get a parsererror error from jQuery. It does not appear to even call my service as I dropped in some code to write a log file to disk and it's not making it there.

The same exact XML should be returned from both my localhost and the server I deployed to.

Any ideas?

like image 201
Alex Avatar asked Apr 06 '10 15:04

Alex


People also ask

What is jQuery AJAX?

AJAX = Asynchronous JavaScript and XML. In short; AJAX is about loading data in the background and display it on the webpage, without reloading the whole page. Examples of applications using AJAX: Gmail, Google Maps, Youtube, and Facebook tabs. You can learn more about AJAX in our AJAX tutorial.

Is jQuery and AJAX same?

AJAX is a web development technique for making asynchronous calls to the server. jQuery is a JavaScript library for designing and make some web development tasks easy. It makes it possible to run javascript outside of the browser. It works on the browser or outside the browser also.

Is jQuery AJAX still used?

It's still used on a lot of websites, so you might end up needing to work with it for maintenance projects or whatever, but for new projects? No way. JQuery was created to deal with a whole bunch of browser incompatibilities that just don't exist in modern browsers.

Is AJAX better than JSON?

JSON is not using for only designing the web page. In fact, JSON sometimes not at all using for the web application. AJAX is using for designing the web page properly, especially where the page needs some server-side data without refreshing the same.


1 Answers

I found the answer to this. After some debugging with Firebug I noticed that the server was throwing back some error HTML. I looked at my server side error logging and the exception was "Request format is unrecognized."

After a bit of digging around I discovered that the following change to the web.config corrects the error:

<system.web>                
<webServices>
    <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
    </protocols>
</webServices>
</system.web>

Now I am a bit interested in the fact that my localhost does not have that web.config entry and works regardless. If anyone understands that a little better I'd like to know why.

Thanks for all the suggestions.

like image 155
Alex Avatar answered Sep 20 '22 11:09

Alex