[英]AJAX Load Content
我完全不知道如何使用AJAX。 查找了一些教程,所有的教程似乎都很混亂。 我遇到了問題:[ 腳本只運行一次 ]。
我將使用它來重新加載頁面,如下所示:[ http://www.roblox.com/Poison-Horns-item?id=62152671 ]這樣我可以獲取最新的商品價格,而無需刷新頁面。 如果有人可以幫助/告訴/指出正確的方向,那將有助於TONS。
我有點像是初學者,所以請耐心等待;)
感謝您的幫助,Alex
AJAX請求與頁面請求(GET和POST)相同,不同之處在於AJAX請求是異步處理的,並且不會離開當前頁面。 響應數據是您要獲取的頁面的來源。 在您解析/使用它之前,該資源是無用的。
一個簡單的jQuery示例:
//for example, we are on example.com
$.ajax({
type : 'get', //the METHOD of the request, like the method of the form
url : 'index.php' //the url to fetch
data : { //additional data which is synonymous to:
query1 : 'foo', // - url queries
query2 : 'bar', // - form inputs
query3 : 'baz',
},
success : function(resposeText){ //response text is the raw source of the fetched resource
$(element).html(responseText); //use response as HTML for element
}
});
//this is similar to requesting:
http://example.com/index.php?query1=foo&query2=bar&query3=baz
同意約瑟夫。 您可以通過javascript方式或jQuery使用ajax,我個人建議jQuery,因為它易於實現。
$.ajax({
type: 'GET',
url: "URL you want to call" ,
data: 'Data you want to pass to above URL',
cache: true, //to enable cache in browser
timeout: 3000, // sets timeout to 3 seconds
beforeSend: function() {
//when ur ajax call generate then u can set here loading spinner
},
error: function(){
// will fire when timeout is reached
},
success: function(response){
//in response you can get your response data from above called url.
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.