GM_xmlhttpRequest数据属性不起作用

时间:2016-07-27 16:55:19

标签: javascript c# asp.net greasemonkey

我使用油脂猴子脚本只是将GM_xmlhttpRequest发送到我本地托管的asp.net网络服务。数据属性不起作用,我查看了github存储库,但没有发现任何人提到任何问题。

有一些StackOverFlow帖子说,添加Content-Type可以解决问题,但对我来说却没有。

这是我的GM_xmlHttpRequest

(function() {
  console.log("Start Of Request");
  GM_xmlhttpRequest({
  method: "GET",
  url: "http://localhost:8807/api/justSayHello",
  data: "input=hello",
  headers: {
    "Content-Type": "application/x-www-form-urlencoded"
  },
  onload: function(response) {
    alert(response.responseText);
  },
   onerror:    function(reponse) {
       console.log("error: ", reponse);
   }
  });
    console.log("End Of Request");
})()

这是我的网络服务

  [HttpGet]
        public JsonResult justSayHello(string input)
        {
            if (input == null)
            {
                return Json("Did you just speak?", JsonRequestBehavior.AllowGet);
            }
            if (input.Equals("hello"))
            {
                return Json("hello back!", JsonRequestBehavior.AllowGet);
            }
         return  Json("eh? Did you say something?", JsonRequestBehavior.AllowGet);
        }

结果是"你刚才说话了吗?"我期待的是"你好"

快速修复

如果我只是在末尾连接查询字符串,那么它工作正常,但我想使用提供的数据属性。

" http://localhost:8807/api/justSayHello?input=hello"

1 个答案:

答案 0 :(得分:0)

好的,问题解决了,问题是数据属性仅适用于帖子请求。获取从查询字符串中读取的请求。

我将此更改为发布请求而不是获取并且它完美运行

相关问题