how to pass a value to jQuery Ajax success-handler

后端 未结 3 799
忘了有多久
忘了有多久 2021-01-13 17:23

Give the following Ajax call in jQuery:

  {
  .
  .
  .
  ,
  getSomeData: function(args, myUrl, foo) {
        $.ajax( {
        type: \"GET\",
        url:         


        
3条回答
  •  感情败类
    2021-01-13 18:00

    If you declare myHandler within the request, you can use a closure.

    getSomeData: function(args, myUrl, foo) {
            $.ajax( {
            type: "GET",
            url:  myUrl,
            data: args,
            async: true,
            dataType: 'json',
            success: function (data, textStatus, oHTTP){   ...   }  
    
             });
     },
    

    this way, foo will be available to you inside the success callback.

提交回复
热议问题