[英]Load HTML inside a div via AJAX
i have
bone.php
andforum.php
我有bone.php
和forum.php
i want to send data to
forum.php
frombone.php
when i click#result
viaAJAX
当我通过AJAX
单击#result
时,我想将数据从bone.php
发送到forum.php
forum.php
gets data and does its job inside server and creates anHTML
pageforum.php
获取数据并在服务器内完成其工作,并创建一个HTML
页面i want this
HTML
page insidebone.php #result
. 我想要这个HTML
页面在bone.php #result
。Is this possible? 这可能吗?
i wrote codes like that. 我写了这样的代码。
$.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 );
},
})
I am getting this messsage Undefined index: webpage_id in \\forum.php on line 15
. 我Undefined index: webpage_id in \\forum.php on line 15
得到此消息Undefined index: webpage_id in \\forum.php on line 15
。 However i am sending data. 但是我正在发送数据。 What could be the problem? 可能是什么问题呢?
What is more interesting is it gives no error and loads the forum.php
correctly. 更有趣的是它没有错误,并且forum.php
正确加载forum.php
。 It just doesn't see the data. 它只是看不到数据。
To start with, 首先,
$('#result').load("forum.php");
this is an ajax call by itself. 这本身就是一个ajax调用。
$.ajax({
url: "forum.php",
success: function( data ) {
$('#result').html(data);
});
Equilevant to this. 与此相关。
you're performing the request twice, when you do $('#result').load("forum.php");
当您执行$('#result').load("forum.php");
时,您将执行两次请求 in the success block, you're actually running the request a second time. 在成功块中,您实际上是在第二次运行请求。 You can do this: 你可以这样做:
$('#result').load("forum.php?webpage_id=" + webpage_id);
Or you can do this: 或者您可以这样做:
$.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 );
},
})
Try 尝试
$.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 );
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.