2012-06-12 40 views
0

是否有任何解决方案来检测POST是否与jQuery一起发送?检测POST是否发送

我的情况是,我有一个WP插件(联系表7),它通过jQuery ajax函数发送数据。当窗体填权(验证)的用户应该被发送到第X页

我有没有什么好结果如下尝试:

if ($(".wpcf7-mail-sent-ok").is(":visible")){ 
     window.location.href = "http://stackoverflow.com"; 
    }); 

我认为这并不因为类工作“wpcf7-mail-sent-ok”只有在表单被发送并且jQuery有效时才会显示。因此,我的上述代码没有被“检测到”。

我该如何解决这个问题?

+0

你能提供一个你的ajax脚本的一部分 – mgraph

+0

什么是在窗体的动作? – swapnesh

+0

不知道你需要哪个代码,所以我发布了漏洞插件:http://pastebin.com/wMk8xHdw – JohnSmith

回答

0

您可以使用DOMNodeInserted事件检测DOM插入。如果您认为wpcf7-mail-sent-ok仅在ajax调用后插入,那么您可以绑定此事件。

$(document).on('DOMNodeInserted', '.wpcf7-mail-sent-ok', function() { 
    window.location.href = 'http://stackoverflow.com' 
}) 
+0

live is depricated“从jQuery 1.7起,不再使用.live()方法。使用.on()附加事件处理程序。旧版jQuery的用户应该优先使用.delegate().live()。” – Thomas

+0

谢谢。我更新了这个例子。 – z33m

+0

谢谢你! – JohnSmith

0

您可以使用类似于Fiddler的东西来检查流量或Chrome - >右键单击 - >“检查元素” - >“网络”。

0

在你的页面上找到ajax并寻找它的success函数,并在里面放一个alert('hello'),你会知道它是否被执行。

1
if($(".wpcf7-mail-sent-ok").length) 
+0

没有工作,我很害怕。我认为这是因为另一个jQuery函数生成“wpcf7-mail-sent-ok”而不重新加载页面。所以你写的代码不能找到它,因为它不在源代码中。 – JohnSmith

+0

它应该检测DOM中的任何内容,不管它到达那里的方式。 – Thomas

相关问题