I am working with a variable named sid
that represents the number of seats. My goal is to pass sid
to the test
method in the TryJSON.aspx
file, manipulate the data within the method, and then return the result to the ajax call. However, I encountered an error when attempting to pass the sid
variable.
var sid = jQuery(this).attr('id');
console.log(sid);
$.ajax({
url: "TryJSON.aspx/test",
type: "POST",
data: JSON.stringify({ 'noSeat': sid }),
contentType: "application/json; charset=utf-8",
success: function (response) {
var arr = JSON.parse(response.d);
console.log(arr);
},
error: function () {
alert("sorry, there was a problem!");
console.log("error");
},
complete: function () {
console.log("completed");
}
});
This is the C# code used to receive the noSeat
parameter:
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public static string test(string noSeat)
{
// return noSeat;
//JavaScriptSerializer serializer = new JavaScriptSerializer();
// return new JavaScriptSerializer().Serialize(new { noSeat = noSeat });
}
I have tried returning just the noSeat
as well as using JavaScript serializer, but I keep getting the error message:
An attempt was made to call the method 'test' using a POST request, which is not allowed.
Even when I attempted to return "Success !!" it did not appear in the console and the error persisted. What could be causing this issue?