Skip to content

Instantly share code, notes, and snippets.

@navinthenapster
Created January 1, 2018 08:35
Show Gist options
  • Save navinthenapster/39a79fc6619d9f54cf5e8c51d35bd8c8 to your computer and use it in GitHub Desktop.
Save navinthenapster/39a79fc6619d9f54cf5e8c51d35bd8c8 to your computer and use it in GitHub Desktop.
Perform Ajax Call from JSP pages to controller or servlet in request.getParameter and return a JSON object from controller.
$scope.sendmessage= function(from,to,msg,status){
$.ajax({
type: 'POST',
url: '<%=request.getContextPath()%>/MainController',
data: {
"from" : from,
"to" : to,
"message" : msg,
"action": "sendmsg",
"status" :status
},
dataType: 'json',
success: function(data) {
console.log(data);
$scope.message=data.message;
alert($scope.message);
//KEY VALUE PAIR -> used to form grid of incoming data dynamically.
$scope.keys=Object.keys($scope.message);
$scope.$apply();
},
error: function(jqXHR, textStatus, errorThrown){
$scope.message="Internal Server Error. Please try again later.";
$scope.$apply();
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment