in controller i want query database and send 2 dimensional array data to view and traverse it every 2 second with javascript! when i send data like below command
// in your view file :
<script type="javascript/text">
var myJsArray = <?php echo CJSON::encode($2dimentionalArray); ?>; // but why it's starts witch "2"
//here use myJsArray as a normal js variable . js timer is ok
</script>
and additional i think you want use ajax to query the 2dimentionalArray every 2 seconds ?
//js side
function repeatRequest(){
var url = "<?php echo $this->createUrl('someActionId'); ?>";
$.post(url,function(response){
// handle the response here !
here use js timer to repeat this function again !(2 seconds latter )
});
}
repeatRequest(); // start it
// server side :
public function someAction(){
// query db
echo CJavaScript::encode($resultSetFromDb);
die();
}
// you may need to put this action to accessRules or check if it is ajax request
I query the database in my php code and save it in 2dimensional array and send this array to view file.In view file i get data from this 2dimesional array with setTimeout function of java script to get vehicle location every 2 seconds and create route of vehicle.
Is this approach true?I don’t want to query database every 2 seconds and send request to server!.Is this approach true for speed up application?