Jquery对话框:表单提交

我正在尝试使用jquery对话框进行搜索表单。 请参阅下面的完整计划。 我的电脑上运行的服务器和http:// localhost / search 。 很少有人怀疑

  1. ajax调用有问题,因为我收到错误消息。 我也尝试了GET请求。
  2. 在chrome中,服务器上的请求类型是POST,但在Iceweasel(Firefox)中它是OPTIONS
  3. 在Iceweasel(Firefox)中,模态窗口保持打开状态,并显示错误。 但在谷歌浏览器中,模态窗口关闭。 这可能是相关的2
  4. 以下javascript代码有什么问题。 我不是JS的专家。

非常感谢你,
BSR。

     
jQuery(document).ready( function(){ jQuery("#myButton").click( showDialog ); $myWindow = jQuery('#myDiv'); $myWindow.dialog({ width: 400, autoOpen:false, title:'Hello World', overlay: { opacity: 0.5, background: 'black'}, buttons: { "Submit Form": function() { $('form#myform').submit();}, "Cancel": function() {$(this).dialog("close");} } }); }); var showDialog = function() { $myWindow.show(); $myWindow.dialog("open"); } var closeDialog = function() { $myWindow.dialog("close"); } var successFn = function (response) { $("#myform").parent().html('').html(response); } var errorFn = function (xhr, ajaxOptions, thrownError){ $("#myform").parent().html('').html(xhr.statusText); } $('form#myform').submit(function(){ $.ajax({ type: 'post', dataType: 'html', url: '/search', async: false, data: $("#myform").serialize(), success: successFn, error: errorFn }); });

你可能需要这个。

 // include modal into form $(this).parent().appendTo($("form:first")); 

编辑:

有了这个,您可以将对话框添加到表单中,从而可以进行postBack

您可以在Open事件中添加它。

尝试使用json作为dataType, jSon是一个使用ajax =)的神奇工具