我有一個JavaScript頁面調用PHP頁面。如何只迴應結果,而不是在Ajax調用的整個頁面
$.getJSON('result.php', function(json){
var data = json.result[0];
}).complete(function(){
// do this
}).error(function(jqXHR, textStatus, errorThrown) {
// do this
});
這是result.php怎麼看起來像
require_once('config.php');
header("Content-type: application/json; charset=UTF8");
$apiMgr = new API(0, 0, array("result"));
$apiResult = $apiMgr->callAPI('GET', 'result', isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/historical' ? '?option=follow' : null, null);
echo $apiResult;
在配置頁面我添加了一些JavaScript腳本像follwoing
<script>
// script
// script
// script
// script
</script>
問題是$ .getJSON()提供我的語法錯誤,因爲從result.php的整個響應還包括不應該在那裏的腳本部分。
我只想回顯或返回$ apiResult不是整個頁面。我希望如果不清楚,我會解釋我的問題,我會盡力解釋它。
有什麼建議嗎?
我嘗試過,但事實並非如此工作。我只是想知道爲什麼?我究竟做錯了什麼? – Shaonline