Ajax request using jquery
$.ajax({
type : "POST",
url : "/login",
cache: false,
data : {userId:'test-user' , timestamp:'20121119'},
dataType: 'json',
success: function (data) {
$.each(data, function(index, element) {
alert(index+" and "+element);
});
},
error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
Comments
Post a Comment