How would I pass in various types of data via AJAX .post()?

Go To StackoverFlow.com

0

I am trying to pass in mutliple data into AJAX .post(). This is what I've done so far:

$('form#tutorTableForm').live('submit', function()
{
    var cid = $('#courseSelect').val();
    var lid = $('#lessonSelect').val();
    var lessonCount = $('#lessonSelect option:selected').attr('id');
    $.post('', $(this).serialize(), function(response){
        alert(response);

    });
    return false;    
});

I want to also pass in cid and lid. How would I do that?

I'm using live instead of on because our app is using the old version.

2012-04-04 21:04
by Johnathan Au
ajax posts are covered all over the web in tutorials. also your question isn't very good - Timmerz 2012-04-04 21:07
You can post code in a code block (it'll even syntax highlight it!) - you don't need to use pastebin. : - Xenon 2012-04-04 21:22


1

I guess you could create an object that contains all the data, like this:

var cid = $('#courseSelect').val();
var lid = $('#lessonSelect').val();
var lessonCount = $('#lessonSelect option:selected').attr('id');

var postdata = { 
          formdata: $(this).serialize(), 
          cid: cid, 
          lid: lid 
        };

$.post('', postdata, function(response){ alert(response); });
2012-04-04 21:08
by Christofer Eliasson


0

place them inside the form as input hidden or whatever and the serialize should add them automatically. without seeing your html it's a bit difficult to see exactly what you need.

2012-04-04 22:12
by Timmerz
Ads