我有一個問題,我的網頁,第一個代碼(姑且說是hompe.php)如何在ajax上獲得另一個頁面?
<html>
<div id="trackingkp"></div>
</html>
然後在我的AJAX我有這樣的代碼,這些
$(document).ready(function() {
var dataString = '';
$.ajax
({
type: "POST",
url: host+"ajax/tracking/kp",
dataType: 'html',
success: function(html)
{
$('#trackingkp').html($(html).find('#trackingkp').html());
//$("#trackingkp").html($(data).find('#trackingkp').html());
}
});
});
和我的AJAX控制器我不喜歡這些(我使用框架laravel)
public function tracking($url)
{
//var_dump("AAA");
$this->view('ajax/tracking/'.$url,[]);
}
在我的AJAX /跟蹤鑑於這樣
<?php
//$json = array();
$json = "<input type='text'></input>";
echo json_encode($json);
?>
當我嘗試正在顯示
Syntax error, unrecognized expression: "<input type='text'>
我已經解決了這個問題,我使用的是另一種選擇,而無需使用jQuery的,所以在同一時間,對控制器時加載視圖home.php,我嘗試把負載視圖太喜歡這些
public function index(){
is_header();
$this->view('home',[]);
$this->view('ajax/tracking/kp',[]); ---> I add these
is_footer();
}
和AJAX /跟蹤/ KP(視圖)我把這些代碼
<input type='text'></input>
並正在工作。
當你試過更換,會發生什麼'已''到'< input type ='text'/>''而不是你的'$ json'變量? – eeya
@eeya:語法錯誤,無法識別的表達式:「」。 – Wolfzmus
嗯,仔細檢查一下:'echo json_encode(「」)''。它仍然返回一個[語法]錯誤? – eeya