我有
bone.php和forum.php当我单击通过forum.phpbone.php的#result时,我想从AJAX发送数据到AJAXforum.php获取数据并在服务器内完成其工作,并创建一个HTML页面。 我要把这个HTML页面放在bone.php #result里面。 这个是可能的吗?
我写了那样的密码。
$.ajax({
url: "forum.php",
data: 'webpage_id='+webpage_id ,
success: function( ) {
$('#result').load("forum.php");
},
error: function( xhr, status, errorThrown ) {
alert( "Sorry, there was a problem!" );
console.log( "Error: " + errorThrown );
console.log( "Status: " + status );
console.dir( xhr );
},
})我收到了这封信Undefined index: webpage_id in \forum.php on line 15。不过,我正在发送数据。有什么问题吗?
更有趣的是,它没有给出错误,并正确加载forum.php。它只是没有看到数据。
发布于 2015-11-15 22:48:22
您要执行两次请求,当您在成功块中执行$('#result').load("forum.php");时,实际上是第二次运行请求。你可以这样做:
$('#result').load("forum.php?webpage_id=" + webpage_id); 或者你可以这么做:
$.ajax({
url: "forum.php",
data: 'webpage_id='+webpage_id ,
success: function(data) {
$('#result').html(data);
},
error: function( xhr, status, errorThrown ) {
alert( "Sorry, there was a problem!" );
console.log( "Error: " + errorThrown );
console.log( "Status: " + status );
console.dir( xhr );
},
})发布于 2015-11-15 22:48:02
首先,
$('#result').load("forum.php");
这本身就是一个ajax调用。
$.ajax({
url: "forum.php",
success: function( data ) {
$('#result').html(data);
});对此一视同仁。
发布于 2015-11-15 22:48:57
试一试
$.ajax({
url: "forum.php",
data: 'webpage_id='+webpage_id ,
success: function(response) {
$('#result').html(response);
},
error: function( xhr, status, errorThrown ) {
alert( "Sorry, there was a problem!" );
console.log( "Error: " + errorThrown );
console.log( "Status: " + status );
console.dir( xhr );
}
});https://stackoverflow.com/questions/33725969
复制相似问题