开发者

jQuery $.get fails

I am using $.get to send and receive the response from my php file. When I visit get-ratings.php, it outputs the response normally. Then when I use jquery, it just fails completely.

These are the firebug logs

Params:

ids fymCtKsm71o,C-4JaNph8Lw,wjdUA2Ws7To,8MTKCig_8SM,2EGJzw3ksYo,vs7NPsSiNv4,MhfJs6ZyWtQ,5QJnPIOqqdw,1lh9rsqOoVM,uMPQTvmOzMM,wpZHXP-hbnU,qUQsKUglv0g,Zt1Z7TYztcA,3UrXj43ORPg,YWSG9Mo4GQQ,LCqr4ZU0t3M,71YsRO6G7Ks,8HZPb7ulu08,rnkn1lVGE2Q,bRNkJM264Kk,nbsmonNnbBQ,HsTlpMPWHlA,FbsgHbXubGU,D9DkciMTsLI,2j3afn_On6I,ofmSvHGCPQE,EBWo-F2G4Wg,b5pGmQXQdF8,v-1EaCwJkKk,ccGKGkkhGZo,JYArUl0TzhA,VwMSsicKRYI,hy4hKG1A0T8,21y8qdoAUI8,

Headers

Date    Mon, 01 Aug 2011 21:41:31 GMT
Server  Apache/2.2.19 (Unix) mod_ssl/2.2.19 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
X-Powered-By    PHP/5.3.6
Keep-Alive  timeout=5, max=100
Connection  Keep-Alive
Transfer-Encoding   chunked
Content-Type    text/html
Request Headers
Host    
User-Agent  Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Accept  */*
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
DNT 1
Connection  keep-alive
Referer 
Origin  

The response is empty and next to the url it has this with a red x开发者_如何学Python

200 OK 9.23s

Even when I set my php file to just echo a simple line of text, it fails.

This is the jquery code I am using

        $.get("get-ratings.php", { ids:vidIds.trim(",") }, function(data){
            console.log("MADE IT: " + data);
        });

I am calling this code from a javascript file that is included into a different domain than the get-ratings.php is hosted on.

Ive tried using $.post and $.ajax and both failed as well.


Cross domain requests will generally fail. Use getJSON.


Cross-domain policy limitations... Modern browsers do not allow XHR requests to domains other than that the page is hosted on.

If you have access to the PHP file, you can use a technique like in JSONP: Instead of AJAX, make a new script element , set the path to the php file as a source and append the script element to the document. And then, in php file, wrap the output in a "javascript function".

var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "get-ratings.php";
$("head").append(script);

Create a new js function

window.complete = function(data){
  //do your stuff here with data received;
}

and finally the php code

instead of just "echo $data", use

echo "complete('.$data.')";
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜