How to test your Ajax call using JSP

If you building the web app and want to test your Ajax call by calling the controller here is the snippet you can use.

$(document).ready(function() {
$.ajax({
type: "GET", 
url: "/YourControllerURL"
}).done(function(data) {
console.log(data);
});
});
  1. place the snippet inside the tag inside JSP
  2. in chrome press F12 for developer tools in chrome.
  3. navigate to console tab
  4. in browser navigate to JSP with snippet code.

 

Alternatively, you can view the navigation tab inside the developer tools and see your ajax request and response from controller.

Sweetness of this approach compared to Postman, is that you don’t need to provide all the authorization details.

Note: for testing purpose change your controller to GET method

Note 2: great article to learn about Ajax methods:

https://learn.jquery.com/ajax/jquery-ajax-methods/

Also if you need to pass data to your controller you can use bellow snippet. It returns json, of course your controller must return json too.


var data = {some data you need for your controller ex. id}
$(document).ready(function() {
$.ajax({
type: "GET", 
url: "/YourControllerURL",
contentType: "application/json",
dataType: "json",
data:data
}).done(function (nameOfJsonControllerReturns){ 

console.log(nameOfJsonControllerReturns.data); 

}); 
}); 
Advertisements

Steps to follow after adding new column to table

To add new column to table follow this steps:

  1. write the sql statement
  2. test it in workbench
  3. add it to sprint x->new.sql
  4. add the rollback statement that removes the column to sprint x->rollback.sql
  5. edit the corresponding XXX_init.sql, so that once init runs, it will not be confused with new column

Small hint:

How to copy data from one column to another:

update TABLE set destinationColumn=copyFromColumn;

for this to work remove the safe update from workbench settings.

Edit->Preferences->SQL editor, untick safe updates, reconnect to db