简体   繁体   English

如何使这个 jQuery ajax 函数与 jQuery 1.12.x 一起工作

[英]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.我有一些带有 jQ​​uery 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.

相关问题 从Jquery 1.11.0和Jquery UI 1.10.4升级到Jquery 3.x和Jquery UI 1.12.x时测试向后兼容性问题 - Testing Backward Compatibility issues while Upgrading from Jquery 1.11.0 and Jquery UI 1.10.4 to Jquery 3.x and Jquery UI 1.12.x 如何使Javascript AJAX函数(带有JQuery)与onclick一起使用? - How to make a Javascript AJAX function (w/ JQuery) to work with onclick? 如何使 Jquery .load() 函数工作一次和 Ajax 请求一次? - How to Make Jquery .load() function work once and Ajax request once? 延迟功能无法在jQuery 1.12的IE中正常工作 - Deferred function doesn't work as expected in IE with jQuery 1.12 Firefox 29.0.x上的Firebug 1.12.x中无法看到控制台输出 - Console output not visible within Firebug 1.12.x on Firefox 29.0.x 如何使 onclick function 与 jquery 一起工作? - How to make an onclick function work with jquery? 如何使类似jQuery的功能正常工作? - How to make jquery like function to work? jQuery Ajax函数不起作用 - JQuery ajax function doesnt work 如何使用Ajax和JQuery实现Dependent下拉Zend Framework 1.12表单 - How to implement Dependent drop down zend framework 1.12 form using ajax and JQuery 如何在一个ajax函数完成之前加载jquery函数 - how to make the jquery function load before one ajax function finish
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM