Twiebie |
|
---|---|
I'm trying to get data into a TPL from a PHP file with AJAX. The code I currently have is as following: This is the JavaScript bit: $(document).ready(function() { function updateTesting(){ ajaxSend({ method: "GET", url: 'index.php?r=test&a=update', data: "", divId: 'test_div' }); } updateTesting(); And test.ajax.php: if ($a == 'update') { foreach ($res->fetchAll() as $row) { $t->assign(array( 'TEST_USERNAME' => cot_build_user($row['test_userid'], htmlspecialchars($row['test_username'])), 'TEST_MESSAGE' => cot_parse($row['test_message'], $cfg['plugin']['comments']['markup']), 'TEST_DATE' => cot_date('M jS', $row['test_date']), 'TEST_DATETIME' => cot_date('G:i', $row['test_date']) )); $t->parse('MAIN.TEST_ROW'); } } The TPL: <!-- BEGIN: MAIN --> <div id="test_div"> <!-- BEGIN: TEST_ROW --> {TEST_USERNAME} {TEST_MESSAGE} {TEST_DATE} {TEST_DATETIME} <!-- END: TEST_ROW --> </div> <!-- END: MAIN -->
For some reason it just doesn't display what I assign to MAIN.TEST_ROW. When I do a simple echo for testing like shown below it does output the data in the TPL with AJAX. if ($a == 'update') { foreach ($res->fetchAll() as $row) { echo $row['test_message']; } } Thanks. Added 1 hours later: Hmm, it sort of works when I add to the foreach loop both parse and out: $t->parse('MAIN.TEST_ROW'); $t->out('MAIN.TEST_ROW'); But I'm wondering if this is the correct way? Added 2 days later: Bump. |
|
This post was edited by Twiebie (2012-10-03 17:46, 11 years ago) |