简体   繁体   中英

AJAX Load Content

Im completely lost on how to work 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. if anyone could help/tell/point me in the right direction, it'd help TONS.

Im somewhat a beginner scripter, so be a little patient ;)

Thanks for any help, Alex

AJAX requests are the same as page requests (GET and POST), except that they are handled asynchronously and without leaving the current page. 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:

//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.

$.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.
        }
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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