Search code examples
jqueryajaxtabular

jQuery using $.ajax


I have a table with some tabular data in it.

Currently I am using the below code to get information from the document rows.html but if I change it from $.get to $.ajax I loose the information from rows.html why?

$.get('rows.html', function(r){ //or $.post, $.ajax etc
      $('table.bordered').append(r);
}); 

Solution

  • $.ajax requires a type field to be populated with something like GET, POST, etc. Since you're fetching data, it seems like you need type: 'GET'. $.post won't help you and if you really want to use $.ajax, you'll need to specify the type (again, GET). http://api.jquery.com/jQuery.ajax/

    EDIT: It appears $.ajax will do a GET by default, but try placing everything in a hash,

    $.ajax({url: 'rows.html', type: 'GET'}, function(r) { 
        alert(r); 
    });