weixin_33749242 2016-01-13 20:19 采纳率: 0%
浏览 32

jQuery未定义数据

So, I have the following js:

function RHP_AJAX(a, b, c)
{
jQuery.ajax({
    type : 'POST',
    url  : custom.ajax_url, 
    data : { 'action': a , id: b},
    success : function(data){
        c;          
        return false;
    }                   
}); 
}

Then another var:

jQuery(document).on( 'click', '.show', function(e) {
   var c = jQuery('.extra').html(data);
   RHP_AJAX('ajax', id, c);
});

The issue is .html(data); as data is not yet defined. I know the issue but I am not sure how to describe it (I am sure you guys will understand when you see the code).

How do I address the issue?

  • 写回答

5条回答 默认 最新

  • 狐狸.fox 2016-01-13 20:25
    关注

    You are looking for a function parameter:

    function RHP_AJAX(a, b, c){
      jQuery.ajax({
        type : 'POST',
        url  : custom.ajax_url, 
        data : { 'action': a , id: b},
        success : c                   
      }); 
    }
    

    and you can use it like this:

    jQuery(document).on( 'click', '.show', function(e) {
       RHP_AJAX('ajax', id, function(data){
           jQuery('.extra').html(data);
       });
    });
    
    评论

报告相同问题?