Skip to content
Wolfy87 edited this page Nov 18, 2010 · 3 revisions

$.ajax(string method, string file, string data, function callback)

Parameters

method - The method in which you want the data to be sent, can either be POST or GET. It is case insensitive.

file - The name of the file you want the data to be sent to.

data - The data you wish to be sent. If set to false then nothing will be sent.

callback - The function to be called when the request completes. If set then it becomes an asynchronous request.

Return values

The contents of the file.

Examples

Post data to a file and show its output.

alert($.ajax('POST', 'myFile.php', 'name=oliver&age=16'));

Get a file and show it via an asynchronous request.

$.ajax('GET', 'someFile.txt', false, function(data) {
    alert('File contains: ' + data);
});