2015-11-25 2 views
6

sto sviluppando un progetto RESTFul web service che ha un POJO come di seguito:Ajax chiamata a lavorare su Google Chrome, ma non su IE 11

@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. 
} 

mio Ajax è sempre chiamato su questo pulsante:

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

la classe Controller che ho è il seguente:

@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); 
    } 
} 

il Service Class per lo stesso è la seguente:

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; 
} 
} 

Dentro il mio JAVA Script mia ajax chiamata al di sopra è:

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'); 

Avendo questo come il mio codice mia applicazione sta lavorando bene su Google Chrome ma a volte funziona ea volte non su Internet Explorer 11. Questo è lo strano comportamento. E l'altra cosa che non riesco a ottenere è anche se funziona su Chrome la chiamata ajax sempre ricevendo il alerts in errore. Qualcuno può spiegare perché è così? E come lo risolvo? Qualsiasi aiuto molto apprezzato. Aggiornamento

Ecco l'output sul network --> Response scheda su Chrome quando viene generata l'errore. Ma nonostante ciò ottengo ancora l'output. enter image description here

Molte grazie

+0

Puoi provare a utilizzare le richieste 'POST' invece di' PUT'. –

+0

@MadushanPerera Se uso 'POST' o' PUT' sta dando lo stesso problema. Ma per 'GET' non sta funzionando su nessuno dei browser e dando errore' nessuna valida alternativa all'input '' ' – tpsaitwal

+0

potresti fornire la risposta del server dalla scheda 'Rete' del browser Chrome. – MeetJoeBlack

risposta

7

Come posso vedere la tua Button type="submit". Se si trova all'interno dello form tag, chiamare lo ajax request nel file action. Come posso vedere dai commenti sopra questo potrebbe essere il problema. Mentre stai inviando qualcosa, questa viene modificata in una richiesta POST e non nella richiesta GET in modo che non sia possibile fornire il metodo di errore. E guardando la soluzione basta cambiare il Button type='button' o chiamare il ajax su action di form tag. Dovrebbe funzionare.