简体   繁体   English

javascript从表单打开模式窗口

[英]javascript open modal window from form

So, I'm very new with Javascript and Jquery and got this terrible old webshop in my lap. 因此,我对Javascript和Jquery还是很陌生,并且把这个可怕的老网上商店放在了我的腿上。 It's basic structure is a form and two buttons, each button update's the "action" attribute and then submit the form, like this.. 它的基本结构是一个表单和两个按钮,每个按钮更新其“ action”属性,然后提交表单,如下所示。

<form id="orderform" name="order" action="javascript:inspect()" method="post">
    ...
    <input type="button" id="btnOrder" value="Order" name="btnOrder">
    <input type="submit" id="btnInspect" value="Inspect" name="submitButtonInspect">
    ...
</form>

With some feeble jquery I set each buttons "click" to call for functions that do some pre-work and then submit the form. 使用一些微不足道的jQuery,我将每个按钮设置为“单击”,以调用需要做一些事前准备然后提交表单的函数。 My problem is how to get the "Inspect" button to show the returning html in a dialog instead of a window? 我的问题是如何获取“检查”按钮以在对话框而不是窗口中显示返回的html?

function inspect() {
    $("#orderform").attr("target", "_blank");
    $("#orderform").attr("action", "/order/inspectorder.p");
    $("#orderform").submit();
};

Some rapid googling gave me this hint, but I can't manage how to get that puzzle to work. 一些快速谷歌搜索给了我这个提示,但是我无法解决如何使这个难题起作用。 I need to submit the form to the inspectorder.p server-code, who will return correct html, but how to get that one into a modal dialog?? 我需要将表单提交给inspectorder.p服务器代码,后者将返回正确的html,但是如何将其放入模式对话框?

$("#dialog").load('myfunction.p', function() {
$(this).dialog({
    modal: true,
    autoOpen: true, 
    closeOnEscape: true,
    height: 200
});

Any advice is much welcome, I suck on web and javascript :( Regards! 任何建议都非常欢迎,我在Web和javascript上很烂:(问候!

Since you are using jquery already, you can use ajax method for form submission eg 由于您已经在使用jquery,因此可以使用ajax方法提交表单,例如

   $.ajax ({
    type: 'POST' ,
    url : '/order/inspectorder.p' , 
    data : $("#orderform").serialize() ,
    success : function (data){
        alert (data) ; // this is the returned data
     }, 
    error : function (jqXhr, status, errorthrown){
        alert(errorthrown); // if an error ocurs 
     }
   })

you can process the returned result in success. 您可以成功处理返回的结果。 If your are using jquery 1.8+ then the callbacks are different but it still works. 如果您使用的是jQuery 1.8+,则回调函数会有所不同,但仍然可以使用。 try this out. 试试这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM