PDA

View Full Version : Issue "Ext.util.JSONP.request" only request remote server on the first time running



vienln
1 Sep 2011, 10:31 AM
I have some code in javascript:


Ext.util.JSONP.request({
url: 'http://mysite.com/data.php',
callbackKey: 'callback',
callback: function(data) {
alert(data.title);
}
});

And php:


<?php
$callback = $_REQUEST['callback'];
$output = array('title' => 'Apple');
if ($callback) {
header('Content-Type: text/javascript');
echo $callback . '(' . json_encode($output) . ');';
} else {
header('Content-Type: application/x-json');
echo json_encode($output);
}

// file test.txt for checking php file has called
$fp=fopen("test.txt", a);
fwrite($fp, " call me");
fclose($fp);
?>

When function js runs on the first time, test.txt is "call me". But when function js runs on the second time, test.txt is still "call me". I think test.txt must be "call me call me", because I have called php two times. This shows that "Ext.util.JSONP.request" only requests remote server on the first time running. The next times it will take the previous data, but do not call the server again.
Any body help me?

arthurakay
1 Sep 2011, 1:43 PM
Although I'm no PHP expert, it looks like you fopen() call is not sending a string as its second argument. Maybe changing that to "a" will help?

A quick look at you JS makes me think it's ok.

vienln
2 Sep 2011, 2:44 AM
Although I'm no PHP expert, it looks like you fopen() call is not sending a string as its second argument. Maybe changing that to "a" will help?

A quick look at you JS makes me think it's ok.
I sure php file runs exactly.
I think "Ext.util.JSONP.request" has some issues about request remote server.
The first call, test.txt is "call me", the second,.... it is still "call me". If I reload page, the first call is "call me call me" and next call is still "call me call me",.... issue???????

vienln
2 Sep 2011, 4:59 AM
This is answer:
http://stackoverflow.com/questions/7282469/issue-ext-util-jsonp-request-only-request-remote-server-on-the-first-time-runni
It is very usefull!

arthurakay
6 Sep 2011, 8:00 AM
Ah, it's caching issue.

My apologies for not recognizing that sooner... the ScriptTagProxy (which uses JSONP) automatically disables caching, so situations like this are avoided by default. I'm glad you found the answer.