Results 1 to 2 of 2

Thread: jQuery .post multiple callback

  1. #1
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default jQuery .post multiple callback

    im using jQuery's post for some ajax calls and get a callback from my php file using echo then in jQuery data to represent that echo.
    question: how can i have multiple variables from php to jQuery?
    do i need to make an array to json file?

    jQuery:
    Code:
    $('.myClass').click(function() {
    	var itm = $(this).find('textarea[class=typeItem]');
    	var txt = $(this).find('textarea[class=typeTxt]');
    	
    	$.post( 'action.php', {itemType:itm, entryItm:txt}, function(data, otherData, moreData){
    		$('ul#mylist).append("<li class='default'>'" + txt + " " + data + otherData + moreData +"'</li>");
    		
    	});
    }
    php:
    Code:
    <?php
    $type = $_POST['itemType'];
    $nTitle = $_POST['entryItm'];
    
    // some code
    
    echo var1; // data
    echo var2; // otherData
    echo var3; // moreData
    
    ?>
    Last edited by ggalan; 12-07-2011 at 02:38 AM.

  2. #2
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    from jQuerys site

    js:
    Code:
    function clicked() {
    	$.post("mainProcess.php", { "func": "getNameAndTime" }, function(data){
    		$('div.container').append(data.name + ' ' + data.time);
    	}, "json");	
    }
    $('#btn').click(function(){
    	clicked();
    });
    php:
    Code:
    $n = 'john';
    $t = '3pm';
    echo json_encode(array("name"=>"$n","time"=>"$t"));

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •