简体   繁体   English

找不到wordpress页面中的jquery ajax错误

[英]jquery ajax in wordpress page not found error

this link from ajax call ajax call from this page此链接来自 ajax调用来自此页面的 ajax 调用

output page输出页面

 $('#sw_stop,#cd_stop').live('click', function() { clicks += 1; if (clicks>=10) { clicks=10; var alt="Kick Count Completed!"; $("#alert").show(); document.getElementById("alert").innerHTML=alt; $.APP.stopTimer(); var h=$("#sw_h").text(); var m=$("#sw_m").text(); var s=$("#sw_s").text(); alert(s); //var name=$("#name").val(); //var message=$("#message").val(); $.ajax({ type:"POST", url:"http://www.mummycenter.com/kick-ajax/", data:{hour:h,minute:m,second:s}, success:function(data){ $("#info").html(data); } }); } document.getElementById("clicks").innerHTML = clicks; });

above code for jquery ajax this code page not found error please help me.上面的jquery ajax代码没有找到这个代码页错误请帮助我。

You're adding jquery library from external source, but wordpress by default adds jquery to the page.您正在从外部源添加 jquery 库,但 wordpress 默认将 jquery 添加到页面。 Loading it twice is not efficient, and might give conflicts, so either disable that in wordpress, or just don't add the external script source.加载两次效率不高,可能会产生冲突,所以要么在 wordpress 中禁用它,要么不添加外部脚本源。

The jquery that comes with wordpress runs in no-conflict mode, meaning that you can't use the $ shorthand. wordpress 自带的 jquery 在无冲突模式下运行,这意味着你不能使用$简写。 Instead you must use jQuery .相反,您必须使用jQuery You can use the $ in your code if you wrap it inside如果将它包装在里面,则可以在代码中使用 $

jQuery(document).ready(function($) {
  // your $ code here
});

.live is deprecated in v1.7 and removed in v1.9. .live在 v1.7 中被弃用,在 v1.9 中被移除。 Use .on instead.使用.on代替。

thanks for comment but problem is pre-defined keyword "hour","minute" that's why ajax not called but by renaming this pre-define keyword now work perfectly感谢您的评论,但问题是预定义的关键字“小时”,“分钟”,这就是为什么没有调用 ajax 但通过重命名这个预定义关键字现在可以完美地工作

 $('#sw_stop,#cd_stop').live('click', function() { clicks += 1; if (clicks>=10) { clicks=10; var alt="Kick Count Completed!"; $("#alert").show(); document.getElementById("alert").innerHTML=alt; $.APP.stopTimer(); var h=$("#sw_h").text(); var m=$("#sw_m").text(); var s=$("#sw_s").text(); alert(s); //var name=$("#name").val(); //var message=$("#message").val(); $.ajax({ type:"POST", url:"http://www.mummycenter.com/kick-ajax/", data:{ho:h,mi:m,se:s}, success:function(data){ $("#info").html(data); } }); } document.getElementById("clicks").innerHTML = clicks; });

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

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