Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

84 lines (58 sloc) 1.741 kB

Prevel Framework Ajax


pl.toParams(Object)

Makes a param-string from the Object.

Example:

alert( pl.toParams({ name: 'Roger', age: 45 }) ); // name=Roger&age=45

pl.ajax(params)

Creates an Ajax-request.

params properties.

  • url

  • type - by default is POST. POST or GET are availiable.

  • dataType - by default is text. text or json (JSON will be parsed automatically) are availiable.

  • async - by default is true. Turns asynchronous on or off.

  • charset - by default is UTF-8. Charset.

  • data - data which will be transferred.

  • load - function which will be called on request loading.

  • success - function which will be called when success request.

  • error - function which will be called when error (403, 404, ...).

Examples of usage:

  // Example #1
  pl.ajax({
    async: true,

    url:      'prevelAjaxTest.py',
    type:     'POST',
    dataType: 'json',
    charset:  'utf-8',

    data: {
      name: 'Abdala',
      id: 1
    },

    load: function() {
      alert('Ajax request is in load...');
    },
    success: function(json) {
      alert('Ajax request was completely successfull!');
    },

    // If dataType equals "json", response text of the error will be parsed as JSON
    error: function(errorNum, json_error) {
      alert('Error #' + errorNum + ': ' + json_error);
    }
  });

  // Example #2 
  pl.ajax({
    url:  'prevelAjaxTests.py',
    type: 'GET',
    data: 'name=Abdala&id=1',

    success: function(text) {
      alert('Server\'s answer: ' + text);
    },

    error: function(errorNum, errorText) {
      alert('Error #' + errorNum + ': ' + errorText);
    }
  });
Jump to Line
Something went wrong with that request. Please try again.