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」
嘗試尋找在提琴手或在瀏覽器的devtools網絡面板發出的請求。並嘗試「POST」方法。 – wOxxOm