3

I recently started making web-based apps with JQTouch. In this app, when a button is pressed, I'm making an ajax request that gets a xml-file from my Linux server which runs Apache. When I run my app over wifi, everything is working great. When I'm over 3g and I press the button, it also loads. But when I go back and press the button again, I get an alert with error 412: precondition failed. I've searched on internet about this error and I found that I have to disable mod_security on my server, but that doesn't solve the error :(

Here's my ajax request:

$.ajax(
{
    type: "POST",
    cache: false,
    url: "http://draughtsonline.no-ip.org/ArtObject/catalogus/catalogus.xml",
    dataType: "xml",
    success: function(xml) 
    {
        // do stuff with the xml file
    },
    error: function(xhr, ajaxOptions, thrownError)
    {
        alert(xhr.status);
        alert(thrownError);
    },
    async: false
});

I really don't know what's wrong with it. Could anyone please help me?

Thanks in advance!

Devos50
  • 2,025
  • 4
  • 25
  • 56
  • Well, it looks like I solved the problem by changing the method from POST to GET. I used post because I had some caching problems when using GET; when I adjusted the xml file, I didn't get the new xml file when I used GET but the old one. I bypassed this by using the cache: false parameter :) Maybe there's anyone who can tell me why POST would give this error? – Devos50 Mar 02 '12 at 21:03

1 Answers1

5

You can't POST using jQuery cross-domain. It's a security feature of JavaScript.

An alternative is to use GET and JSONP instead of POST and XML or use a relative URL.

More information:

Community
  • 1
  • 1
Rick Burns
  • 1,538
  • 16
  • 20