PDA

View Full Version : Resolved jQuery .post multiple callback



ggalan
12-07-2011, 12:22 AM
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:


$('.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:


<?php
$type = $_POST['itemType'];
$nTitle = $_POST['entryItm'];

// some code

echo var1; // data
echo var2; // otherData
echo var3; // moreData

?>

ggalan
12-07-2011, 02:37 AM
from jQuerys site

js:


function clicked() {
$.post("mainProcess.php", { "func": "getNameAndTime" }, function(data){
$('div.container').append(data.name + ' ' + data.time);
}, "json");
}
$('#btn').click(function(){
clicked();
});


php:


$n = 'john';
$t = '3pm';
echo json_encode(array("name"=>"$n","time"=>"$t"));