简体   繁体   English

AJAX加载内容

[英]AJAX Load Content

Im completely lost on how to work AJAX. 我完全不知道如何使用AJAX。 Looked up some tutorials and all seemed pretty confusing. 查找了一些教程,所有的教程似乎都很混乱。 I ran into the problem: [ Script only runs once ]. 我遇到了问题:[ 脚本只运行一次 ]。

I would use it to reload pages like so: [ http://www.roblox.com/Poison-Horns-item?id=62152671 ] so I could get the latest item prices, without refreshing the page. 我将使用它来重新加载页面,如下所示:[ http://www.roblox.com/Poison-Horns-item?id=62152671 ]这样我可以获取最新的商品价格,而无需刷新页面。 if anyone could help/tell/point me in the right direction, it'd help TONS. 如果有人可以帮助/告诉/指出正确的方向,那将有助于TONS。

Im somewhat a beginner scripter, so be a little patient ;) 我有点像是初学者,所以请耐心等待;)

Thanks for any help, Alex 感谢您的帮助,Alex

AJAX requests are the same as page requests (GET and POST), except that they are handled asynchronously and without leaving the current page. AJAX请求与页面请求(GET和POST)相同,不同之处在于AJAX请求是异步处理的,并且不会离开当前页面。 The response data is the source of the page you wanted to fetch. 响应数据是您要获取的页面的来源。 That source is useless until you parse/use it. 在您解析/使用它之前,该资源是无用的。

A simple jQuery example: 一个简单的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

agree with joseph. 同意约瑟夫。 You can use ajax by javascript manner or by jQuery, I personally suggest jQuery because it is simple to implement. 您可以通过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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM