简体   繁体   English

在 Jquery 中将事件应用到动态添加表单时遇到一些问题

[英]Getting some problem with apply event to dynamic added form in Jquery

I am loading the form in dialog box via jQuery我正在通过 jQuery 在对话框中加载表单

The code is like代码就像

<form class ="form1" action="" method="post" enctype="multipart/form-data" >
...
</form>

I am using jQuery form plugin to submit form like this我正在使用 jQuery 表单插件来提交这样的表单

$(".form1").live('submit', function(e) {   

    var options = { 
        target:        '.ajaxMessage',  
        beforeSubmit:  showRequest,  
        success:       showResponse,
        type: 'POST'

    }; 
    alert('test');                          
    $(this).ajaxSubmit(options); 
    return false;                                         
});

Now现在

  1. If i load the form directly without AJAX and then i submit the form then form gets submiited successfuly without any problem.如果我在没有 AJAX 的情况下直接加载表单,然后我提交表单,那么表单将成功提交,没有任何问题。 It works 10 out of 10 times它在 10 次中有 10 次有效

  2. In second case I load the form dynamically.在第二种情况下,我动态加载表单。 When i click on form link then i load the form dynamically in a jquery dialog box then if i click on submit form then i can see the alert but form is not submitted.当我点击表单链接然后我在 jquery 对话框中动态加载表单然后如果我点击提交表单然后我可以看到警报但表单没有提交。 But it works sometimes but sometimes not.但它有时有效,但有时无效。 I would say it work 2 times out of 10.我会说它在 10 次中有 2 次有效。

Firebug console is also not showing any error Firebug 控制台也没有显示任何错误

Is there any way i can find whats problem有什么办法我可以找到什么问题

Firebug will usually (I actually think not at all) won't show any errors for a ajax call, instead the error will be in the ajax request(still in firebug). Firebug 通常(我实际上根本不认为)不会显示 ajax 调用的任何错误,而是错误将出现在 ajax 请求中(仍在 firebug 中)。 Click the request and then response.单击请求,然后响应。

My guess is that there is a problem with the params you are sending or there is something wrong with what you a returning(ie you return html when ajax is expecting json, this will cause success never to be fired)我的猜测是您发送的参数有问题,或者您返回的内容有问题(即,当 ajax 期待 json 时,您返回 html,这将导致永远不会被解雇,

Also, try to pass an error:function(jqXHR, textStatus, errorThrown){} to the ` ajaxSubmit params and see what happens.此外,尝试将error:function(jqXHR, textStatus, errorThrown){}传递给 `ajaxSubmit 参数,看看会发生什么。

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

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