开发者

Issue "Ext.util.JSONP.request" only request remote server on the first time running

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. Anybody help me?


Try adding the time as an param to prevent this 'caching', worked for me in my previous project

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜