JQuery Ajax-Aufruf von httpget webmethod (c #) funktioniert nicht
Ich versuche, eine Ajax zu einer Webmethode im Code dahinter zu bekommen. Das Problem ist, ich bekomme immer wieder den Fehler "Parserror" von der jQueryonfail
Methode
Wenn ich GET in POST ändere, funktioniert alles einwandfrei. Bitte beachten Sie meinen Code unten.
Ajax Call
<script type="text/javascript">
var id = "li1234";
function AjaxGet() {
$.ajax({
type: "GET",
url: "webmethods.aspx/AjaxGet",
data: "{ 'id' : '" + id + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function(msg) {
alert("success");
},
error: function(msg, text) {
alert(text);
}
});
}
</script>
Code Behind
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod(UseHttpGet = true,
ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
public static string AjaxGet(string id)
{
return id;
}
Web.config
<webServices>
<protocols>
<add name="HttpGet"/>
</protocols>
</webServices>
Die verwendete URL
........ / webmethods.aspx / AjaxGet? {% 20% 27id% 27% 20:% 20% 27li1234% 27}
Als Teil der Antwort wird der HTML-Code für die Seite webmethods zurückgegeben.
Jede Hilfe wird sehr geschätzt.