2016-07-27 43 views
0

我正在使用一個黃油猴腳本來簡單地將GM_xmlhttpRequest發送到我本地託管的asp.net Web服務。數據屬性不起作用,我查看了github存儲庫,並沒有發現任何人提及任何問題。GM_xmlhttpRequest數據屬性不起作用

在那裏有幾個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"); 
})() 

,這裏是我的web服務

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

結果 「你剛纔說話嗎?」而我會想到的是「你好」

速戰速決

,如果我只是concatanate上年底的查詢字符串,然後它工作正常,但我想使用提供的數據屬性。

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

+1

嘗試尋找在提琴手或在瀏覽器的devtools網絡面板發出的請求。並嘗試「POST」方法。 – wOxxOm

回答

0

好了,問題解決了,問題是,數據屬性只適用於職位的請求。獲取請求從查詢字符串中讀取。

我把它改爲POST請求,而不是GET和它完美的作品