Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery ajax cross domain call and permission issue

I have this polling script to check if a text file is created on the server. Works great locally, but fails when the file is on a different domain. How would i rewrite this for cross domain support?

$.ajax({ 
    url: 'http://blah.mydomain.com/test.txt', 
    type: "GET", 
    success: function(result) { 
        //Success!
        window.location.replace(Successful.aspx');
    }, 
    error: function(request, status, error) { 
        setTimeout("VerifyStatus(" + pollingInterval + ")");
    }
    });

EDIT: I ended up using YQL to solve the cross domain issue and although it works, YQL is really slow that's adding quite a bit of performance overhead. Can anyone suggest a better solution for cross domain JQuery calls?

like image 917
Nick Avatar asked Feb 04 '10 02:02

Nick


3 Answers

Set the dataType to "JSONP" on your $.ajax() call. You'll have to make sure the response is properly formatted for it to work. Wikipedia has a good section on JSONP.

like image 187
Tim R Avatar answered Sep 18 '22 22:09

Tim R


Ajax doesn't go cross domain. Your best bet is to create a php page on the local domain that does the check, and go to -that- with your ajax call.

like image 38
monksp Avatar answered Sep 17 '22 22:09

monksp


To get cross-domain AJAX via jQuery, you might want to check this out: http://github.com/jamespadolsey/jQuery-Plugins/tree/master/cross-domain-ajax/

like image 37
Horia Dragomir Avatar answered Sep 17 '22 22:09

Horia Dragomir