Ajax 调用在 Google Chrome 但不在 IE 11 上工作

Ajax call working on Google Chrome but not on IE 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.
}

我的 ajax 在这个按钮上被调用:

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

我的Controllerclass如下:

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

Service Class 如下:

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

在我的 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');

将此作为我的代码,我的应用程序在 Google Chrome 上运行良好,但有时在 Internet Explorer 11 上运行有时不运行。这是奇怪的行为。另一件我无法得到的事情是,即使它在 Chrome 上工作,ajax 调用总是让 alerts 出错。谁能解释为什么会这样?我该如何解决?非常感谢任何帮助。 更新

这是抛出错误时 chrome 上 network --> Response 选项卡上的输出。但尽管如此,我仍然得到了输出。

非常感谢

如我所见Button type="submit"。如果它在 form tag 内,则在文件的 action 中调用 ajax request。正如我从上面的评论中看到的那样,这可能是问题所在。当您提交某些内容时,这会更改为 POST 请求而不是 GET 请求,因此不允许提供错误方法。查看解决方案只需更改 Button type='button' 或在 form tagaction 上调用 ajax。它应该工作。