jquery ajax错误帮助 [英] jquery ajax error help

查看:74
本文介绍了jquery ajax错误帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$("#form1").submit(function(e){
    e.preventDefault();
    });
    $("#submit").click(function(e){
    dataString = $("#form1").serialize();
    var new = $("input#new").val();
    dataString = "new=" + new;
    $.ajax({
    type: "POST",
    url: "Servlet",
    data: dataString,
    dataType: "json",
    success: function( data, textStatus, jqXHR) {
    //our country code was correct so we have some information to display
    if(data.success){
    $("#ajaxResponse").html("");
    $("#ajaxResponse").append("Country Code: " + data.countryInfo.code + "
    ");
    }
    //display error message
    else {
    $("#ajaxResponse").html("<div>Category Name is invalid!</div>");
    }
    },
    error: function(jqXHR, textStatus, errorThrown){
    console.log("Something really bad happened " + textStatus);
    $("#ajaxResponse").html(jqXHR.responseText);
    },
    //capture the request before it was sent to server
    beforeSend: function(jqXHR, settings){
    //adding some Dummy data to the request
    settings.data += "&dummyData=whatever";
    //disable the button until we get the response
    $('#submit').attr("disabled", true);
    },
    //this is called after the response or error functions are finsihed
    //so that we can take some action
    complete: function(jqXHR, textStatus){
    //enable the button
    $('#submit').attr("disabled", false);
    }
    });
    });

推荐答案

#form1)。submit( function (e){
e.preventDefault();
});
("#form1").submit(function(e){ e.preventDefault(); });


#submit)。 click( function (e){
dataString =
("#submit").click(function(e){ dataString =


#form1)。serialize();
var new =
("#form1").serialize(); var new =


这篇关于jquery ajax错误帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆