警报不能处理错误消息

时间:2018-01-30 07:42:16

标签: javascript jquery html ajax

//警报没有处理错误消息,我想只插入少数4个问题,之后它应该不起作用。



success: function(msg, String, jqXHR) {
    window.location = 'home.html';


    $("#result").html(msg, String, jqXHR)
    alert("Data Uploaded: ");

    if (msg.success == 'Error') {

      alert("Please close the previous issue");

      window.location = 'home.html';
    }




// here(msg.success =='错误')无法正常工作我想显示此消息 - "请关闭上一期"对此。

1 个答案:

答案 0 :(得分:0)

希望这适合你。

$(document).ready(function(){
$('#your_form').submit(function(event) {
     event.preventDefault();
     dataString = $("#your_form").serialize();
     $.ajax({
        type: "post",
        url: "post.php",
        dataType:"json",
        data: dataString,
        success: function (response) {
            if(response.status === "success") {
                // do something with response.message or whatever other data on success
                alert("Data Uploaded: ");
                window.location='home.html';
            } else if(response.status === "error") {
                alert("Please close the previous issue");

                 window.location='home.html';
            }
        }
    })
    return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>