Koiw
Koiw

Reputation: 17

Real-time load result (ajax)

I dont know how write this script. I need load results with some URL (eg: localhost/index.php?action=get&type=29) and this result to give a variable for further processing. I need create this on Jquery. Thanks.

Upvotes: 1

Views: 4152

Answers (3)

hvgotcodes
hvgotcodes

Reputation: 120188

you can use

$.ajax({
    url: "localhost/index.php",
    data: "action=get&type=29",
    success: function(data, status, xhr){
       // data is the response from the server, status is the http status code, 
       // xhr is the actual xhr
    },
    error: function(){
    },
    ...
});

to get the results.

Be sure to define the success and error callbacks to process the data when it is returned.

Look here http://api.jquery.com/jQuery.ajax/ to get started.

Upvotes: 0

MacMac
MacMac

Reputation: 35301

There are features in jQuery that can be used, you have either a quick load using the simple .load() function that will parse the HTML into an element. Usage:

$('#element').load('http://www.urlgoeshere.com/');

With processing events with AJAX with further writing options, you have many options to choose from:

These options below are using the .ajax() function but makes the writing easier:

EDIT: With your "refresh", you can use the setTimeout function to repeat the ajax call:

setTimeout(function()
{
    $.ajax({
        type: "POST",
        url: "some.php",
        data: "action=get&type=29",
        success: function(arg){
            // do something
        }
    });
}, 1000); // This will "refresh" every 1 second

Upvotes: 2

Matthew Riches
Matthew Riches

Reputation: 2286

$.ajax({
    type: "POST",
    url: "some.php",
    data: "action=get&type=29",
    success: function(arg){
        // do something
    }
});

Upvotes: 0

Related Questions