I'm currently utilizing a grease monkey script to send a GM_xmlhttpRequest to my locally hosted asp.net web service. However, I've encountered an issue with the data attribute not functioning properly. Despite checking the Github repository, I have found no mention of this problem.
Although some StackOverflow posts suggest that adding a Content-Type may resolve the issue, it has not worked for me personally.
Below is my GM_xmlHttpRequest code snippet:
(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");
})()
And here is the corresponding web service implementation:
[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);
}
The current result displayed is "Did you just speak?" whereas I would expect it to return "hello".
A potential workaround
If I simply append the query string at the end, everything works smoothly. However, I prefer utilizing the provided data attribute.