[英]How to make this jQuery ajax function work with jQuery 1.12.x
I have some ajax function with jQuery 1.5.x, i need upgrade to jQuery 1.12.x but this jquery function not working.我有一些带有 jQuery 1.5.x 的 ajax 函数,我需要升级到 jQuery 1.12.x 但这个 jquery 函数不起作用。
function vpb_add_to_cart(post_title,post_id,guid,status)
{
$("div.checkout_user_info").hide();
$("div#checkout_user_info").hide();
$("div.shopping_cart_status").show();
$("div#shopping_cart_status").show();
var dataString = "post_title=" + post_title + "&post_id=" + post_id + "&guid=" + guid + "&page=add_to_cart";
$.ajax({
type: "POST",
url: "http://localhost/www/opsional/wp-compare.php",
data: dataString,
beforeSend: function()
{
$('html, body').animate({scrollTop:0}, 'slow');
$("#response").html('<img src="loading.gif" align="absmiddle" alt="Loading..."> Loading...<br clear="all" /><br clear="all" />');
},
success: function(response)
{
$("#response").html(response);
}
});
}
Pickup data with this;用这个拾取数据;
<input type="button" id="vasplus_p_blog_add_to_cart_button" value="Add to Cart" title="Add this item to cart" onclick="vpb_add_to_cart('Samsung Galaxy Note 3','2688','http://localhost/www/opsional/wp-content/uploads/2016/12/Samsung-Galaxy-Note-3-2-4-150x150.jpg','add');" />
How to make all above code work with jQuery 1.12.x Thanks, please help.如何使上述所有代码与 jQuery 1.12.x 一起工作 谢谢,请帮忙。
It isn't a problem with your JavaScript, but rather with the instantiation of jQuery.这不是 JavaScript 的问题,而是 jQuery 的实例化问题。 You may have multiple instances of jQuery on the page, or you may possibly have an issue returning the jQuery library.
您可能在页面上有多个 jQuery 实例,或者您可能在返回 jQuery 库时遇到问题。 If you're getting a message about the $ itself then the problem lies outside of your function.
如果您收到有关 $ 本身的消息,则问题出在您的函数之外。
I would make sure that you're not loading a second version of jQuery and that you're not loading a library that might compete with jQuery and/or take over the $.我会确保您不会加载第二个版本的 jQuery,并且不会加载可能与 jQuery 竞争和/或接管 $.
You could test this by replacing your "$" indicators with "jQuery" instead.您可以通过用“jQuery”替换“$”指标来测试这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.