Bitte den Code aus meiner MVC-Ansicht sehen:AJAX gibt undefined zurück
<script type="text/javascript" src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
function GetMessage() {
$.ajax({
type: "GET",
url: "http://localhost/webapi/api/Values/",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess(),
async: false,
failure: function (response) {
alert('there was an error creating the disposal decision records')
}
});
function OnSuccess() {
return function (response) {
alert(response.d);
}
}
}
GetMessage();
</script>
und den Code aus: http://localhost/webapi/api/Values/:
public Person Get()
{
Person p = new Person();
p.id = 1;
p.name = "Bert";
p.age = 31
return p;
}
im Ereignishandler Erfolg; undefined wird aufgefordert. Warum?
Was ist "response.d"? – Nic
@Nic, siehe bitte: http://stackoverflow.com/questions/4215386/jquery-ajax-json-response-returns-key-d – w0051977
Probieren Sie 'console.log (Antwort)' und sehen, was es enthält. Alert ist nicht sehr gut zum Debuggen. – JJJ