2017-04-05 40 views
0

這裏是我的代碼:

$.get(site_url+'/core/includes/manipulate_player.php?action=delete&userid='+userid+'&productid='+productid, function(html){ 
     console.log(html); 
//some other code here 
    }); 

我想功能

beforeSend:function() 
      { 
      } 

前添加像$.ajax()

任何人可以幫助我該怎麼做?

+1

爲什麼你沒有使用'$ .ajax()'? – htmlbrewery

+0

我知道我可以用$ .ajax()解決這個問題。但那不是我的問題。假設我使用了$ .ajax()並解決了問題,那麼我也想知道它是如何應用於$ .get()中的。 – Ninja

回答

1

您可以定義調用您的beforeSend函數並獲取請求的函數。像那樣。

function getRequest(url, beforeSend) { 
    beforeSend(); 

    $.get(url, function(response){ 
     console.log(response); 
    }); 
} 


getRequest('www.example.com?a=3', function() { 
    console.log('function call before $.get send'); 
}); 
+0

非常感謝,真的工作 – Ninja