Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery在出错后没有停止,它';s在错误消息后重定向其他页面url_Jquery_Ajax - Fatal编程技术网

jquery在出错后没有停止,它';s在错误消息后重定向其他页面url

jquery在出错后没有停止,它';s在错误消息后重定向其他页面url,jquery,ajax,Jquery,Ajax,我有一个结帐页面,当我提交结帐时会显示一条错误消息,但当我单击错误警报按钮禁用错误消息时,结帐页面上的页面并没有停止,它只是重定向到支付网关页面。我使用此代码将数据发送到我的api $(document).ready(function () { $("#place_order").click(function () { var person1 = new Object(); debugger; var quantity=$('#chec

我有一个结帐页面,当我提交结帐时会显示一条错误消息,但当我单击错误警报按钮禁用错误消息时,结帐页面上的页面并没有停止,它只是重定向到支付网关页面。我使用此代码将数据发送到我的api

 $(document).ready(function () {
    $("#place_order").click(function () {
        var person1 = new Object();

        debugger;
        var quantity=$('#check2').find('#Quantity_number').val();
        if(quantity)
        {

         $('#check2').find('#Quantity').val(quantity.substring(2,quantity.length));
        }

        var amount=$('#check2').find('#Total_amount');
        $(amount).val($(amount).val().substring(1,$(amount).val().length))//replacing Rupee sign

        /* #check1 is form id , for first form , please let me know how two use second form id #check2 */
        var person = {};
        var person1 = {};

         $.map($('#check1').serializeArray(), function(n, i){
           person[n['name']] = n['value'];
         });

         $.map($('#check2').serializeArray(), function(n, i){
            person1[n['name']] = n['value'];
         });

        var mergedFormObj = $.extend({},person,person1);

        $.ajax({
            url: 'http://192.168.1.102:1512/qlikapi/RegisterUser',
            type: 'Post',
            data: mergedFormObj,
            success: function(data, textStatus, xhr) {
                alert(data.ErrorMessage);
                if (data.Success) {
                    document.location.reload();  
                }
            },
            error: function (xhr, textStatus, errorThrown) {
                console.log('Error in Operation');
            }
        });
    });
});   
    </script>
$(文档).ready(函数(){
$(“#下单”)。单击(函数(){
var person1=新对象();
调试器;
变量数量=$('#检查2')。查找('#数量\单位编号')。val();
如果(数量)
{
$('#check2').find('#Quantity').val(Quantity.substring(2,Quantity.length));
}
var金额=$(“#检查2”)。查找(“#总金额”);
$(amount).val($(amount).val().substring(1,$(amount).val().length))//替换卢比符号
/*#check1是表单id,对于第一个表单,请让我知道两个人如何使用第二个表单id#check2*/
var person={};
var person1={};
$.map($('#check1').serializeArray(),函数(n,i){
人[n['name']]=n['value'];
});
$.map($('#check2').serializeArray(),函数(n,i){
person1[n['name']=n['value'];
});
var mergedFormObj=$.extend({},person,person1);
$.ajax({
网址:'http://192.168.1.102:1512/qlikapi/RegisterUser',
键入:“Post”,
数据:mergedFormObj,
成功:函数(数据、文本状态、xhr){
警报(data.ErrorMessage);
if(data.Success){
document.location.reload();
}
},
错误:函数(xhr、textStatus、errorshown){
console.log(“操作错误”);
}
});
});
});   

根据您的代码:

alert(data.ErrorMessage);
if (data.Success) {
    document.location.reload();  
}
当且仅当
数据成功
计算为
时,才会发生重定向。因此,
data.Success
的评估结果似乎是
true
。因此,您有两种选择:

  • 如果服务器返回的数据不正确,请更正服务器端代码以返回您希望它返回的数据
  • 如果无法修改服务器,请通过客户端代码中的服务器端操作找到另一种确定“成功”或“失败”的方法。也许仅仅在
    data.ErrorMessage
    中存在一个非空值就足够了

  • 无论哪种方式,代码都按设计工作。但是数据不是您假设的那样。

    请编辑此代码以返回不正确的数据。David,这有什么样的脚本吗。please@SanjayYadav:什么的示例脚本?您已经拥有的代码是您的代码的示例脚本。您可以编辑此代码,以便在收到错误消息后停止重定向。please@SanjayYadav:如果您根本不希望它重定向,只需删除重定向代码即可。基本上,删除整个
    if
    块。你真的不需要我为你做这件事。您可以在文本编辑器中打开代码并对其进行修改。