Ajax呼叫在谷歌Chrome上运行,但在IE 11上运行

tps*_*wal 6 java ajax rest google-chrome internet-explorer-11

我正在开发一个RESTFul web service项目POJO如下:

@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.
}
Run Code Online (Sandbox Code Playgroud)

我的ajax被调用此按钮:

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

Controller我的课程如下:

@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);
    }
}
Run Code Online (Sandbox Code Playgroud)

Service相同的类如下:

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;
}
}
Run Code Online (Sandbox Code Playgroud)

在我的JAVA Script我的ajax上面呼叫:

    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');
Run Code Online (Sandbox Code Playgroud)

将此作为我的代码我的应用程序正常工作Google Chrome但有时工作,有时不工作Internet Explorer 11.这是一种奇怪的行为.和我无法得到其他的事情是,即使它的工作原理上Chromeajax电话总是得到alerts错误的.任何人都可以解释为什么会如此?我该如何解决?任何帮助非常感谢. 更新

network --> Response是抛出错误时chrome 上的选项卡上的输出.但尽管我仍然得到输出. 在此输入图像描述

非常感谢

The*_*nor 7

我可以看到你的Button type="submit".如果它在里面form tag则调用文件的ajax requestin action.正如我从上面的评论中看到的那样,这可能是个问题.当您提交某些内容时,这会更改为POST请求而不是GET请求,因此不允许使用错误方法.而综观目前的解决方案只是改变Button type='button'或致电ajaxactionform tag.它应该工作.