Created
January 1, 2018 08:35
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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