-4

I am new to the "jQuery ajax", I have the following code.

Can you explain me the code line by line :

        function fun1() {
          $.ajaxSetup({jsonp: null,jsonpCallback: null });

          $.ajax({
             type:'GET',
             url: 'login.action', 
             dataType: 'json',
             data: {
                 age:$("#id2").val()
             },
             success: function(data) {
                 printStudentDetails(data);
             },
             error:function() {
                 alert("failure");
             }
         });
       }  
4

3 回答 3

0

http://api.jquery.com/jQuery.ajax/只需阅读文档

于 2013-10-23T08:41:11.357 回答
0
         $.ajax({              // Beginning of your ajax call
      type:'GET',              // Type can be Get Or Post ie. Your Http Methods
      url: 'login.action',     // This is the Url Which will be called by the ajax it can be your function at server side
     dataType: 'json',         // This is the datatype you are expecting from server in this case its json
    data: {   age:$("#id2").val()  // This is the data you are passing to your url/function


       },

    success: function(data){ printStudentDetails(data); // This is the callback function which will get execute after the success of ajax call

                    },
   error:function() // This is the callback function which will get execute if there is some error is proccesing your request
        { 
          alert("failure");
            }
     });

欲了解更多信息:http ://api.jquery.com/jQuery.ajax/

于 2013-10-23T08:41:57.220 回答
0

这是完整的描述:

  $.ajax({       //this line is used to call the ajax
      type:'GET',   //this is used to define the method either get or post
      url: 'login.action', //here define the url here you want to send the data
      dataType: 'json', //this is datatype to tell what type of data will return values are text,html,json,xml
      data: {'age':$("#id2").val()}, //there define the variable and value of that variable which will send to that page which is define in the url
      success: function(data){ 
         //call when responce is successful
         printStudentDetails(data); 
      },
      error:function()
      { 
         //call when responce has some error
         alert("failure");
      }
  });
于 2013-10-23T08:42:57.987 回答