Ajax call works in Google Chrome, but not in IE 11

I am developing a RESTFul web service project that has a POJO as shown below:

 @XmlRootElement public class Input { //variable declarations public Input(){ //default constructor } //constructor no 1 public Input(String LR, double ECH,double CSH,String APP) { this.LR = LR; this.ECH = ECH; this.CSH = CSH; this.APP = APP; } //constructor no 2 public Input(String LR, double ECH,double CSH,String APP,...) { this.LR = LR; this.ECH = ECH; this.CSH = CSH; this.APP = APP; //constructor of all other parameters including these } //getters and setters method below. } 

My ajax is called on this button:

 <button type="submit" onClick='functionname();' class="btn btn-primary" ><span class="glyphicon glyphicon-lock"></span>Function</button> 

The Controller class I have the following:

 @Path("/input") public class InputResponse { InputService inputservice = new InputService(); @PUT @Path("/approve") @Produces(MediaType.APPLICATION_JSON) public void approveInputRecord(Input obj) throws Exception{ String LR = obj.getLR(); double CSH = obj.getCSH(); double ECH = obj.getECH(); String APP = obj.getAPP(); Input input = new Input(LR,CSH,ECH,APP); input = inputservice.approveTransaction(input); } } 

The Service class for the same type:

 public class InputService { CallableStatement stmt; Statement commitStmt; public InputService(){ //database connection } public Input approveTransaction(Input input) throws SQLException { commitStmt = dcc.con.createStatement(); stmt=dcc.con.prepareCall("BEGIN APPROVRTRANSACTION(?,?,?,?); END;"); stmt.setString(1, input.getLR()); stmt.setDouble(2, input.getECH()); stmt.setDouble(3, input.getCSH()); stmt.setString(4, input.getAPP()); stmt.execute(); commitStmt.executeQuery("COMMIT"); return input; } } 

Inside my JAVA Script my ajax call is above:

  var obj = { LogReference : logreference, EuroclearHoldings:euroclearholdings, ClearstreamHoldings:clearstreamholdings, Approver : loginXPID } var jsonobj = JSON.stringify(obj); $.ajax({ url:'./webapi/input/approve', type: 'PUT', data:jsonobj, cache:false, contentType: 'application/json', dataType:'json', success:function(data) { alert('success'); }, error:function(xhr,textstatus,errorthrown){ alert(xhr.responseText); alert(textstatus); alert(errorthrown); } },'json'); 

Having this as my code, my application works fine on Google Chrome , but sometimes it works, and sometimes not on Internet Explorer 11 . This is a weird behavior. And the other thing that I canโ€™t get, even if it works on Chrome , the ajax call always gets error alerts by error. Can someone explain why this is so? And how to solve it? Any help is greatly appreciated. Update

Here is the output on the network --> Response tab on chrome on error. But despite this, I am still getting a way out. enter image description here

Thank you very much

+6
source share
1 answer

As I can see your Button type="submit" . If it is inside the form tag , then call ajax request in the action file. As I can see from the comments above, this can be a problem. When you send something, it changes to a POST request, not a GET , so its error method is not allowed. And looking at the solution, just change Button type='button' or call ajax on action from the form tag . It should work.

+7
source

All Articles