what im trying to do is to send data in JSON using jquery to server and receive it at server side. After that parse it and use the data and again response back to client in json form. Im using Play(web based framework for java) at server side. Here is my code:
Tier.js
var attribs={
id: document.forms["tier"]["id"].value ,
name: document.forms["tier"]["name"].value ,
limits: document.forms["tier"]["limits"].value
};
$.ajax({
type:"get",
url: "validateTier.json" ,
dataType: "json",
jsonp: 'callback',
data: attribs,
contentType: "application/json; charset=utf-8",
beforeSend: function( xhr ) {
xhr.overrideMimeType( 'application/json; charset=utf-8' );
},
error:function(x,e){
if(x.status==0){
alert('You are offline!!\n Please Check Your Network.');
}else if(x.status==404){
alert('Requested URL not found.');
}else if(x.status==500){
alert('Internel Server Error.');
}else if(e=='parsererror'){
alert('Error.\nParsing JSON Request failed.');
}else if(e=='timeout'){
alert('Request Time out.');
}else {
alert('Unknow Error.\n'+x.responseText);
}
},
success: function(data) {
alert(data.status);
},
}).done(function( msg ) {
alert( "Data Saved: " + msg );
}); // End ajax
at Server side:
Map<String,Object> json = new HashMap<String,Object>();
json.put("status", status);
json.put("message", msg);
renderJSON(json);
Output:
You are offline!! Please Check Your Network.