Basic Simple Asp.net + jQuery + JSON example

后端 未结 3 1962
[愿得一人]
[愿得一人] 2020-11-29 00:48

I\'m trying to learn how to make a simple call to the server from Javascript/jQuery. I\'ve been trying to learn and could not find a tutorial with those simple steps.

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 01:29

    If you are using jQuery you could do it with a GET or POST.

    $.get ('',
           { dateParam: date, stringParam: 'teststring' },
           function(data) {
              // your JSON is in data
           }
    );
    
    $.post ('',
           { dateParam: date, stringParam: 'teststring' },
           function(data) {
              // your JSON is in data
           }
    );
    

    Note that the name of the parameters in (e.g. dateParam, stringParam) need to be the same as the name of the parameters your service method is expecting. Also that your service will need to format the result as JSON, the data parameter in the call back will contain anything your service sends back (e.g. text, xml, json, etc).

    See the jQuery documentation for $.ajax, $.get, $.post: http://api.jquery.com/jQuery.ajax/, http://api.jquery.com/jQuery.get/, http://api.jquery.com/jQuery.post/

提交回复
热议问题