Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
JavaScript
$("#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);
    }
    });
    });
Posted
Updated 23-Oct-14 23:07pm
v3
Comments
Sinisa Hajnal 24-Oct-14 2:56am    
So, what is the error? Where? What is the problem here?
[no name] 24-Oct-14 4:31am    
Ok. Then? What help you need mate?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900