简体   繁体   English

为什么Ajax不遵循成功功能?

[英]Why is Ajax not following success function?

I have done this hundreds of times and it seemed to work like a charm.But I just can't figure what is wrong with this code. 我已经做过数百遍了,看起来好像很吸引人,但是我无法弄清楚这段代码有什么问题。

$.ajax({
        url:"<?php echo base_url() ?>admin/sold_item",
        data:{qty:sold,tprice:sold_price,id:id,uprice:uprice},
        type:"post",
        async:true,
        success:function(msg){

            if(msg=="info_saved"){
                $('#sold_data').html('Your Sold Details Have Been Saved');
                setTimeout("$.colorbox.close()",1500);
              //  setTimeout("window.location.reload()",1800);
            }
            else if(msg=="wrong"){ 
                $('#sold_data').html('Your Information is Incorrect!!Enter Data Again!!');
                setTimeout("$.colorbox.close()",1500);
               // setTimeout("window.location.reload()",1800); 
            }
        }
    })

I am using condition for the response.The php code called by ajax is working perfectly this is the exact code that I am using for ajax.I have alerted the msg variable and firebug console shows the same but the if condition is just not working.What can be the reason.I have tried switch ..case but to no avail.Please somebody see what I am not seeing. 我正在使用条件进行响应。ajax调用的php代码运行正常,这是我用于ajax的确切代码。我已经alerted the msg variable并且firebug console显示了相同的内容,但是if condition却无法正常工作。可能是什么原因。我尝试了..case switch ..case但无济于事。请有人看看我没看到什么。

Use the developer tools in chrome and go to the network tab and then select the XHR button at the bottom left of the screen. 使用chrome中的开发者工具并转到“网络”标签,然后选择屏幕左下方的XHR按钮。 This will show you exactly what is happening and you can read the response or see an error if there is one. 这将准确显示正在发生的事情,您可以阅读响应或查看错误(如果有)。

Your URL seems wrong. 您的网址似乎不正确。 admin/sold_item there is no file extension. admin/sold_item没有文件扩展名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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