我被这个问题困住了,我真的不知道为什么它不起作用。引导弹出窗口内的Ajax
如果我在引导程序的弹出窗口中使用此代码,它可以工作,但只要我在popover内使用它,它就不再工作。我的意思是,如果表单是从弹出窗口提交的,它就像一个正常窗体一样,收取新的页面而不是像AJAX脚本那样操作。
$("#share-popover").submit(function(){
//get the url for the form
var url=$("#form_search").attr("action");
alert($("#search-value").val());
//start send the post request
$.post(url,{
formName:$("#search-value").val(),
other:"attributes"
},function(data){
if(data.responseCode==200){
$('#output').html(data.greeting);
$('#output').css("color","red");
}
else if(data.responseCode==400){ //bad request
$('#output').html(data.greeting);
$('#output').css("color","red");
}
else{
alert("An unexpeded error occured.");
}
});
return false;
});
按钮:
<button id="share-dropdown" style="margin-right:5px" class="btn btn-warning pull-right" type="button" rel="popover" data-placement="bottom" data-html="true"><i class="icon icon-plus icon-white"></i> Share</button>
JS:
$('#share-dropdown').popover({
html : true,
content: function() {
return $("#share-popover").html();
}
});
的HTML内容:
<div id="share-popover" style="display: none">
<form id="form_search" action="{{ path('weezbook_site_ajax_search') }}" method="POST">
<input id="search-value" type="text" value="Book title, authors, isbn" class="share-input" name="search-value" />
<input type="submit" />
</form>
我用这与Symfony2的和我的控制器返回JSON。
我真的不明白为什么它的工作盒子的外面,而不是内部...
没有解决我的问题,但对于试图感谢:) – BaNz 2013-02-15 09:50:41