首页 > 解决方案 > JavaScript 运行时错误:“setTimeout”未定义

问题描述

使用以下代码,我收到错误“JavaScript 运行时错误:'setTimeout' 未定义”。

<form class="paypalform" action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_cart">
    <input type="hidden" name="upload" value="1">
    <input type="hidden" name="business" value="zengxumin@hotmail.com">

    @foreach (var item in Model)
    {
        <input type="hidden" name="item_name_@count" value="@item.ProductName">
        <input type="hidden" name="amount_@count" value="@item.Price">
        <input type="hidden" name="quantity_@count" value="@item.Quantity">
        count++;
    }
        <input type="hidden" name="currency_code" value="USD">
        <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>

<a href="#" class="placeorder btn btn-primary pull-right">Checkout</a>

<script>
$(function () {

$("a.placeorder").click(function (e) {
    e.preventDefault();

    var $this = $(this);

    var url = "/cart/PlaceOrder";

    $(".ajaxbg").show();

    $.post(url, {}, function (data) {
    $(".ajaxbg span").text("Thank you. You will now be redirected to paypal.");

    setTimeout(function () {
            $('form input[name="submit"]').click();
    }, 2000);
    });
});

});
</script>

这些代码应该指向 PayPal 结帐网页。但游行被短信“谢谢。您现在将被重定向到 PayPal”而停止。有什么问题吗?谢谢。

标签: javascriptc#asp.net-mvc

解决方案


推荐阅读