当我不想要时,浏览器会间歇性地显示JSON

时间:2014-03-13 14:41:17

标签: javascript jquery json

我有以下jQuery函数。我不想显示返回的JSON数据。我只想让我的对话框向用户显示一条消息。奇怪的是,有时我会根据需要收到一条对话框消息,有时我会得到一个包含原始JSON响应的页面。什么可能导致这种间歇性问题?

$("#btnSubmit").click(function (event) {
    event.preventDefault();
    $.ajax({
        url: "/Transfer/Receive?TransferID=" + $("#TransferID").val(),
        dataType: "json",
        type: "post",
        success: function (data) {                    
            if (data.Message == "success") {
                $("#divTransferNo").dialog("destroy");

                $("#systemMsg").dialog({ autoOpen: true, title: "System Message", height: 150, modal: true });
                $("#systemMsg").html("<p>Transfer Received Successfully.</p>");
                $('div#systemMsg').bind('dialogclose', function (event) {
                    window.location = "../DrawMandrel/";
                });

            }
            else if(data.Message=="verifyreceiveback") {}
            else if (data.ErrorType == "validation") {
                $("#systemMsg").dialog({ autoOpen: true, title: "System Message", height: 150, modal: true });
                $("#systemMsg").html("<p>ERROR - This transfer has already been received.</p>");
            }
            else {                   
                $("#systemMsg").dialog({ autoOpen: true, title: "System Message", height: 150, modal: true });
                $("#systemMsg").html("<p>ERROR - Check your transfer number.</p>");
            }
        }            
    });
});

更新:

我刚刚收到了下面应该调用的回复:

else {                   
     $("#systemMsg").dialog({ autoOpen: true, title: "System Message", height: 150,   modal: true });
                $("#systemMsg").html("<p>ERROR - Check your transfer number.</p>");


{"Message":"ERROR: This transfer has already been  completed.","ErrorType":"validation","ErrorMessage":"ERROR: This transfer has already been completed.","OperationMessage":"ERROR: This transfer has already been completed.","BarCode":null}

更新:

所以我将我的ajax请求更改为:

 $.ajax({
            url: "/Transfer/Receive?TransferID=" + $("#TransferID").val(),
            dataType: 'json',
            type: 'post',
            accept: {
                json: 'application/json',
                xml: 'application/xml'
            },
            success: function (data) {       

我正在制作以下请求标题:

enter image description here

0 个答案:

没有答案