很抱歉,这个主题的标题可能不正确,但这是我想出的最好的。
所以,我正在为一个网站建立管理面板。
我有一个页面,在页面的某些部分,我想刷新它并加载另一个表单。
比方说添加一个日程表,在页面下面的某个地方,我希望在单击链接时立即显示此表单。
当用户保存它时,我希望该表单消失,而不是有一个显示所有日程安排的列表。

我不想使用框架--我不是框架的支持者。该面板是使用PHP构建的。
也许这可以通过Ajax实现?如果是,->如何?任何链接到好的例子或教程。
发布于 2011-09-28 02:26:49
是的,这将通过ajax解决。
以下是页面应该刷新时的代码示例
$('#button').click(function() {
$.ajax({
url: 'path/to/script.php',
type: 'post',
dataType: 'html', // depends on what you want to return, json, xml, html?
// we'll say html for this example
data: formData, // if you are passing data to your php script, needed with a post request
success: function(data, textStatus, jqXHR) {
console.log(data); // the console will tell use if we're returning data
$('#update-menu').html(data); // update the element with the returned data
},
error: function(textStatus, errorThrown, jqXHR) {
console.log(errorThrown); // the console will tell us if there are any problems
}
}); //end ajax
return false; // prevent default button behavior
}); // end clickjQuery Ajax
http://api.jquery.com/jQuery.ajax/
脚本已解释。
1-用户单击该按钮。
2- Click函数启动对服务器的XHR调用。
3- url是php脚本,它将根据发布的值处理我们发送的数据。
4-类型为POST请求,需要数据才能返回数据。
5-本例中的dataType将是html。
6-我们发送到脚本的数据可能是分配给变量formData的表单元素的序列化。
7-如果XHR返回200,那么在控制台中记录返回的数据,这样我们就知道我们正在处理什么。然后将该数据作为html放入所选元素中(#update-menu)。
8-如果有错误,让控制台为我们记录错误。
9-返回false以防止默认行为。
10 -全部完成。
https://stackoverflow.com/questions/7573243
复制相似问题