and here are the contents of the PHP file
header("Content-Type: application/json");
//header("Content-Type: text/javascript");
$domain_name = $_GET['domain_name'];
$tld = $_GET['tld'];
$开发者_如何学Pythontext = file_get_contents("http://www.some.com/some.php?action=caajax&domain_name=$domain_name&tld=$tld");
echo $text;
earlier i was using "Content-Type: text/javascript" as you can see. But the occurrence of the error was much more. So i tried "Content-Type: application/json" while this greatly reduced the occurrence of the error it did not eliminate it.
I'm still learning a lot of these stuffs.. So any idea why this is happening??
Edit: On Codo's advice i studied the ajax profile using firebug. On a normal successful ajax call there were- params | headers | response | json
But on error there was - params | headers | rewponse | XML
here is the image - http://resources.bigrock.in/affiliate/widgets/img/error_headers.jpg
Your problem is that you are not encoding your response as JSON. Whatever you set in the header needs to be what you echo the content as. Also, text/javascript
isn't really a good header to use. If you are just trying to echo out the html from that link, it should be text/html
.
Here is the code for JSON:
header("Content-Type: application/json");
//header("Content-Type: text/javascript");
$domain_name = $_GET['domain_name'];
$tld = $_GET['tld'];
$text = file_get_contents("http://www.some.com/some.php?action=caajax&domain_name=$domain_name&tld=$tld");
echo json_encode($text);
精彩评论