开发者

JSONP Request In jQuery 1.4.2. Does Not Even Query Remote URL?

I have here a test page that should do a jQuery JSONP cross-domain request not once, but twice:

http://www.starcitygames.com/json_test.php

And it should query this here page here to pull up some test data:

http://scg.im/ajax/fetch_recent_URLs.php?callback=fred

After bashing my head against the wall for an entire morning where I got absolutely zero response from this script, pro or con, I put a mail() call in the fetch_recent_URLs script to mail me whenever the remote page was loaded.

It turns out that despite several loadings, tweaking开发者_运维问答s, etc. of the script, it never actually calls the scg.im page. The script isn't broken, returns no fatal errors in JavaScript, et cetera - it just doesn't actually ever seem to fire the AJAX call.

Even more perplexingly, regular JSON calls (to this domain) work fine.

The script(s) are as such:

$.ajax({
        url: "http://scg.im/ajax/fetch_recent_URLs.php",
        type: "GET",
        dataType: "jsonp",
        error: function(xhr, status, error) {
            alert("error");
        },
        success: function(json) {
            alert("success");
        }
    });


$.getJSON("http://scg.im/ajax/fetch_recent_URLs.php?callback=?",  function(rtndata) {
        alert("Returned!"); 
});

Both are taken from various test pages that claims this works. I've also tried it in jQuery 1.6, changed the header, etc., all encountering the same problem; no matter what I do, jQuery never actually calls the page. (Again, I know this because the script mails me every time it's loaded, and it doesn't email me at all when I load this page.)

Any idea why this is not working? I'm doing, as far as I can tell, everything according to plan (and about five variations on these scripts to boot).

Edit: SOLVED! I figured it out, and it's entirely stupid.

If you have NoScript enabled for FireFox (and you arguably should), AND you have not allowed scripts from the new domain (in this case, scg.im), then NoScript will prevent the domain request before it even begins. Good security. Thoroughly baffling.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜