简体   繁体   中英

jquery ajax in wordpress page not found error

this link from ajax call ajax call from this page

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.

You're adding jquery library from external source, but wordpress by default adds jquery to the page. 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.

The jquery that comes with wordpress runs in no-conflict mode, meaning that you can't use the $ shorthand. Instead you must use 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. Use .on instead.

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

 $('#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; });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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