2012-05-26 251 views
0

我完全失去了如何工作AJAX。看了一些教程,都显得很混乱。我遇到了这个问题:[Script only runs once]。AJAX加载内容

我会用它来重新加载页面,如下所示:[http://www.roblox.com/Poison-Horns-item?id=62152671]所以我可以得到最新的物品价格,而不刷新页面。如果任何人能够帮助/告诉/指向正确的方向,它会帮助吨。

林有些新手编剧,所以要有点耐心;)

感谢您的帮助, 亚历

回答

0

AJAX请求是相同的页面请求(GET和POST),除了他们是异步处理并且不离开当前页面。响应数据是您想要获取的页面的来源。在解析/使用它之前,这个源代码是无用的。

一个简单的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 
+0

因此,如果我想在此页面上重新载入包含'Private Sales'的表格:[http://www.roblox.com/Poison-Horns-item?id=62152671] – Alex

0

同意约瑟夫。您可以通过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. 
     } 
    });