基本上我的页面上有两个滑块,每当它们的值被调整时,它们引用一个脚本,该脚本返回一个JSON数组,其中包含符合新标准的产品的值。
在我的成功回调中,我想调用我的PHP类,它将我的视图呈现到屏幕上(我知道我可能可以在Javascript中实现此效果,但我已经构建了一个PHP类来处理所有所需的逻辑,所以如果有一个快捷方式会更简单。
我的AJAX方法是这样的:function update_results(values)
{
var json = JSON.stringify(values);
$.ajax({
type: "GET",
url: "./app/core/commands/update_results.php?cache=" + (new Date().getTime()),
data: { query : json },
cache: false,
success: function(data) {
// Remove the old data from the document
$('tr').remove();
// Build the new table rows using the returned data array
$('table').append("<?php Table t = new Table(data); ?>");
}
});
}
调用我的表构造函数构建我需要的一切,只是通过传递JSON数组,我收到从我的AJAX调用返回,但是没有什么是呈现到屏幕上的时刻-有任何方法这样做吗?
PHP在服务器上运行…JavaScript在客户端…"<?php Table t = new Table(data); ?>"
不会神奇地与Ajax调用一起工作。当您进行Ajax调用时,服务器应该返回表。