我目前正在学习jQuery,并决定做一个AJAX Post请求的弹出对话框。我已经编码了,但实际上并没有工作。它发送数据,但表单正常工作。我不想让它正常工作,但我试图将数据发布到对话框中的同一页面上。jQuery AJAX发布不起作用
这是我的代码。任何帮助将很好,谢谢!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Welcome to WEBSITE</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<style type="text/css">
body {
background: lightblue;
margin: 50px 0px;
padding: 0px;
}
#newlol {
width: 500px;
margin: 0px auto;
text-align: left;
padding: 15px;
border: 1px solid #000000;
background: #ffffff;
display: hidden;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
z-index: 5000;
margin-top: 90px;
}
#new {
z-index: 3000;
width: 100%;
height: 100%;
opacity: 0.5;
filter: alpha(opacity=50);
-khtml-opacity: 0.5;
display: none;
position: absolute;
top: 0;
left: 0;
}
</style>
<script type="text/javascript">
function newpopup(message){
$('#new').show();
$('#newlol').fadeIn(2000);
if(message == "comment"){
var message = $("#barney").html();
}
$('#newlolmessage').html(message);
$('#searchForm').submit(function(event){
event.preventDefault();
searchresult = $('#searchForm').serialize();
$.ajax({
type: 'POST',
url: 'search.php',
data: searchresult,
dataType: 'json',
success: function(data){
$('#newmessagelol').html(data.name);
}
});
return false;
});
$('#newlolclose').click(function(){
$('#new').hide();
$('#newlol').hide();
});
}
</script>
</head>
<body onload="newpopup('comment');">
<div id="barney" style="display: none;">
<form action="search.php" id="searchForm"><input type="text" name="sally"><br /><input type="submit"></form>
</div>
<a href="#">clickmeeee</a>
<div id="new">
<div id="newlol">
<div id="newlolmessage">
</div>
<div id="newlolclose">Click to close.</div>
</div>
</div>
</body>
</html>
如果您需要,您应该提供比“这是我的代码”更多的信息期待帮助。你的意思是“表格正常工作”是什么意思? – Jon 2011-04-03 15:06:39
当我想让它打开对话框中的页面时,它正在更改页面。说实话很难。 – Joshua 2011-04-03 15:08:05
你确定你没有任何javascript错误吗?听起来好像提交事件从未被注册过。 – 2011-04-03 15:29:21