连接到服务器AJAX调用时出错

时间:2018-06-20 05:46:49

标签: javascript jquery ajax

我下面有这段代码,我正在尝试将数据发送到服务器,但是我唯一要连接的文档是向服务器发送的示例数据,它看起来像这样org.testng.Assert.assertEquals(assert_LoginFailure.getText(),arg1); ,我在做什么吗?这里的我的代码在这里是错误的,因为我不断收到错误405和{“method”:“fruit-post”,“data”:{“red-fruits”:["Apple","Cherry","Tomato"],“green-fruits”:["Grapes","Watermelon"],“yellow-fruits”:["Lemon","Pear"],“purple-fruits”:[]}}任何帮助,将不胜感激

Response for preflight has invalid HTTP status code 405.

2 个答案:

答案 0 :(得分:1)

您的Ajax请求错误。在这里http://api.jquery.com/jquery.ajax/

方法必须为POSTGETPUT

$.ajax({
  url: "LINK",
  method: "POST",
  data: {
        “method”:“fruit-post”,
        “data”:{
            “red-fruits”:["Apple","Cherry","Tomato"],
            “green-fruits”:["Grapes","Watermelon"],
            “yellow-fruits”:["Lemon","Pear"],
            “purple-fruits”:[]
        }
  },
  dataType: "html",
  cache: false,
      success: function(data) {
  }
});

答案 1 :(得分:0)

ajax使用方法type:'get'"post",不需要method在网址中提及您的方法

 $.ajax({
    url: "LINK",
    type: "POST",
    data: {
         "data": fruitString
    },
    dataType: "html",
    cache: false,
    success: function(data) {
  }
 });