So I have seen many examples such as these : https://stackoverflow.com/a/8094230/2525507
public class WebService : System.Web.Services.WebService {
[WebMethod]
public List<string> getList() {
return new List<string> {"I", "Like", "Stack", "Overflow"};
}
}
Where you just it seems that through the success function you can view the returned data from the c# method in the form of an alert. But what if I want to access this "input+1" data outside of the function call, how would I proceed to do that? Also I am not sure how to call a method that has no parameters?
<body>
<select id="wordSelect">
// Drop Down Menu to be populated
</select>
<script>
$(function () {
$.ajax({
url: 'WebService.asmx/getList',
data: '{**NO PARAMETERS?!**}', // should I also call JSON.stringify?
type: 'POST',
dataType: 'json',
contentType: 'application/json',
success: function (data, status) {
alert(data);
alert(typeof data);
}
});
});
$.each(data.i, function(index, item) { // will this access "I", "Like", ... etc?
$(#wordSelect).append(
$("<option></option>")
.text(item)
);
};
</script>
</body>
In the end, I would like to populate a dropdown list using returned JSON data from a c# method that has been called through ajax, but I'm not sure how I can play with that retrieved JSON data that seems to be stuck in the function call?
Sorry, I am new to Jquery/AJAX/etc... But Thank you so much!
successcallback. If you want to do something outside, you have to prepare some callback, add code there and call that callback inside thesuccesscallback.