rsalumpit Posted September 5, 2009 Share Posted September 5, 2009 hi i cant access the function variables when it try to call it again..its a pagination script that uses ajax function to update the query.here is my code index.html <?php require_once (dirname(__FILE__) . '/include_modules/mystore/MyStoreController.php'); $myStoreItems = new myStoreItems(); $myStoreItems->showMyAction($_GET); <? if (count($myStoreItems->store_items)) : ?> <? for ($i = 0; $i < (count($myStoreItems->store_items)); $i++) : ?> some codes here that display the query result.. <? endif; ?> $paginationConfigMyStore=array();//some configs <? pagination_menu("#" , "store" , $myStoreItems->totalPagesMyStore , $myStoreItems->currentPageMyStore, false, $paginationConfigMyStore); ?> ................. /*javascript function that sends $_GET the current page number then call again MyController.php to update the new page content.. */ ?> MyController.php <?php require_once($inc_path . 'Controller.php'); class myStoreItems extends COntroller { public function showMyAction($_GET)//added action { $itemList = new ItemList(); $totalMyStore = $itemList->getUserStoreItemsCount($this->userId); $cp = 0; $np = 0; $start = 0; $limit = 0; $MAX_STORE_ITEMS = 3; old_pagination_adapter($start, $limit, $cp, $np, $totalMyStore, $MAX_STORE_ITEMS, $MAX_STORE_ITEMS, $_GET, 'page'); $this->store_items = $itemList->getUserStoreItems($this->userId, null, array('start' => $start, 'limit' => $limit)); $this->totalPagesMyStore = $np; $this->currentPageMyStore = $cp; } } ?> ajax_function.html <?php require_once(dirname(__FILE__) . '/../include_modules/mystore/MyController.php'); $myStoreItems = new myStoreItems(); $callback_func = array(&$myStoreItems,"showMyStoreAction"); call_user_func($callback_func,$_GET); ?> My problem is when i call again the function($myStoreItems->showMyAction($_GET); ) with the new request using javascript i cant access the vars $myStoreItems->store_items,$myStoreItems->totalPagesMyStore,$myStoreItems->currentPageMyStore again thats why it returns zero result but i debug it and see if the request $_GET was successfully sent and yes it is sent the only problem is that i cant access the vars again using "ajax_function.html" thank you for your time reading my post.. Quote Link to comment https://forums.phpfreaks.com/topic/173176-how-to-call-this-variablehelp-please/ Share on other sites More sharing options...
kratsg Posted September 5, 2009 Share Posted September 5, 2009 I'm wondering how your AJAX calls are set up. a) You use AJAX to send $_GET request to what page? b) The AJAX calls what function when the request is done to update the page? -It seems to me that you're using AJAX to call ajax_function.html but it doesn't seem like you're changing the current page with data received? Quote Link to comment https://forums.phpfreaks.com/topic/173176-how-to-call-this-variablehelp-please/#findComment-912830 Share on other sites More sharing options...
rsalumpit Posted September 5, 2009 Author Share Posted September 5, 2009 I'm wondering how your AJAX calls are set up. a) You use AJAX to send $_GET request to what page? b) The AJAX calls what function when the request is done to update the page? -It seems to me that you're using AJAX to call ajax_function.html but it doesn't seem like you're changing the current page with data received? here is my ajax function function updateMyStoreContent(params) { params.action = "myStoreContentStoreItems"; params.id = userId; params.time = new Date().toString(); new Ajax.Updater($("myStoreContentStoreItems"), "ajax_functions/ajax_function.html", { parameters: params, evalScripts: true, method: "get", onCreate: function(event) { $("myStoreContentStoreItems").update(""); $("myStoreItemsLoader").show(); $("myStoreItemsLoader").scrollTo(); }, onComplete: function(event) { $("myStoreItemsLoader").hide(); } }); } var userId = <?= $store_user_id ?>; $$(".storePageLink").map(function(linkElement) { linkElement.observe("click", function(event) { event.stop(); var page = this.id.substring("storePageLink_".length); updateMyStoreContent({page: page}); }); }); if ($("storePageSelectButton") != null) { $("storePageSelectButton").observe("click", function(event) { event.stop(); var page = $("pgs_id").value; updateMyStoreContent({page: page}); }); } Quote Link to comment https://forums.phpfreaks.com/topic/173176-how-to-call-this-variablehelp-please/#findComment-912839 Share on other sites More sharing options...
kratsg Posted September 5, 2009 Share Posted September 5, 2009 How are you trying to access these variables? Is your AJAX receiving any data to handle? Quote Link to comment https://forums.phpfreaks.com/topic/173176-how-to-call-this-variablehelp-please/#findComment-912846 Share on other sites More sharing options...
rsalumpit Posted September 5, 2009 Author Share Posted September 5, 2009 How are you trying to access these variables? Is your AJAX receiving any data to handle? no i just use $_GET['page'] because thats what i only need..i and i think its sending to MyController.php because i debug it var_dump($_GET) and i updates the new query the only problem is that i cant access the variables i also try to use globals but one effect.. Quote Link to comment https://forums.phpfreaks.com/topic/173176-how-to-call-this-variablehelp-please/#findComment-912851 Share on other sites More sharing options...
kratsg Posted September 5, 2009 Share Posted September 5, 2009 You cannot use JavaScript to access PHP variables. There is a distinction between client-side and server-side. If you want a JavaScript function to obtain data from server-side, you use AJAX calls to a PHP page that outputs the data for the AJAX to receive. Quote Link to comment https://forums.phpfreaks.com/topic/173176-how-to-call-this-variablehelp-please/#findComment-912854 Share on other sites More sharing options...
rsalumpit Posted September 5, 2009 Author Share Posted September 5, 2009 You cannot use JavaScript to access PHP variables. There is a distinction between client-side and server-side. If you want a JavaScript function to obtain data from server-side, you use AJAX calls to a PHP page that outputs the data for the AJAX to receive. i think we're not on the same page..forget about ajax trust me its working all i need to know is how can i access a function variable again after call it using a different php page and return the to index.html look at my diagram: index.html call->mycontroller->showMyAction($_GET); to view default query..variables call successful index.html send->uses ajax script to send $_GET info to update new query->ajax functiom ajax_ajax_function call->mycontroller->showMyAction($_GET);when i try to dispaly the variables back to index.html is seems not working:-( thank you! Quote Link to comment https://forums.phpfreaks.com/topic/173176-how-to-call-this-variablehelp-please/#findComment-912861 Share on other sites More sharing options...
kratsg Posted September 5, 2009 Share Posted September 5, 2009 I'm still slightly confused by the process in how this works. You use $_GET in index.html to showMyAction($_GET) in order to retreive data to display I assume. Then you send $_GET again to update another query? And then you use another page to get index.html's $_GET variables to retreive data to display? I'm not sure quite how these pages are set up.... >.< Quote Link to comment https://forums.phpfreaks.com/topic/173176-how-to-call-this-variablehelp-please/#findComment-912867 Share on other sites More sharing options...
rsalumpit Posted September 5, 2009 Author Share Posted September 5, 2009 I'm still slightly confused by the process in how this works. You use $_GET in index.html to showMyAction($_GET) in order to retreive data to display I assume. Then you send $_GET again to update another query? And then you use another page to get index.html's $_GET variables to retreive data to display? I'm not sure quite how these pages are set up.... >.< im so sorry if im cofussing you i dont own this code too im just helping a friend but it seems i need help also it took me a day to analys this one. the new $_GET values was sent to ajax_function.html by this JS fuction function updateMyStoreContent(params) { params.action = "myStoreContentStoreItems"; params.id = userId; params.time = new Date().toString(); new Ajax.Updater($("myStoreContentStoreItems"), "ajax_functions/ajax_function.html", { parameters: params, evalScripts: true, method: "get", onCreate: function(event) { $("myStoreContentStoreItems").update(""); $("myStoreItemsLoader").show(); $("myStoreItemsLoader").scrollTo(); }, onComplete: function(event) { $("myStoreItemsLoader").hide(); } }); } var userId = <?= $store_user_id ?>; $$(".storePageLink").map(function(linkElement) { linkElement.observe("click", function(event) { event.stop(); var page = this.id.substring("storePageLink_".length); updateMyStoreContent({page: page}); }); }); if ($("storePageSelectButton") != null) { $("storePageSelectButton").observe("click", function(event) { event.stop(); var page = $("pgs_id").value; updateMyStoreContent({page: page}); }); } ajax_function.html will process it call again the mycontroller.php to update the new query with this code: require_once(dirname(__FILE__) . '/../include_modules/mystore/MyController.php'); $myStoreItems = new myStoreItems(); $callback_func = array(&$myStoreItems,"showMyStoreAction"); call_user_func($callback_func,$_GET); and i want it get the new update query by dispalying it to index.html i hope you get my point..thank you! Quote Link to comment https://forums.phpfreaks.com/topic/173176-how-to-call-this-variablehelp-please/#findComment-912872 Share on other sites More sharing options...
kratsg Posted September 5, 2009 Share Posted September 5, 2009 Now I think I get it. So you need ajax_function.html's results to be displayed back in index.html. Simply have the AJAX call to ajax_function.html return the result to update index.html with. Quote Link to comment https://forums.phpfreaks.com/topic/173176-how-to-call-this-variablehelp-please/#findComment-912874 Share on other sites More sharing options...
rsalumpit Posted September 5, 2009 Author Share Posted September 5, 2009 Now I think I get it. So you need ajax_function.html's results to be displayed back in index.html. Simply have the AJAX call to ajax_function.html return the result to update index.html with. how can i do that?please? Quote Link to comment https://forums.phpfreaks.com/topic/173176-how-to-call-this-variablehelp-please/#findComment-912877 Share on other sites More sharing options...
kratsg Posted September 5, 2009 Share Posted September 5, 2009 Well, quite simply, the way an AJAX call works is outlined like so: 1. AJAX request is initiated. 2. Variables/Parameters are sent to said page. 3. Said page processes and echos out data. 4. Said data is received and handled by the original AJAX call. In your case, ajax_function.html will need to output whatever you want to use in displaying content on index.html. Index.html contains the ajax call which you will need to use to handle the data received. I can't teach you AJAX, the point is to help you with bugs and such E_E Quote Link to comment https://forums.phpfreaks.com/topic/173176-how-to-call-this-variablehelp-please/#findComment-912881 Share on other sites More sharing options...
rsalumpit Posted September 5, 2009 Author Share Posted September 5, 2009 is that the only way i can do this? Quote Link to comment https://forums.phpfreaks.com/topic/173176-how-to-call-this-variablehelp-please/#findComment-912884 Share on other sites More sharing options...
kratsg Posted September 5, 2009 Share Posted September 5, 2009 .. Yes. What you're trying to do is have JavaScript access something on PHP Side which is only done via AJAX calls. You cannot use JavaScript to access PHP variables. There is a distinction between client-side and server-side. If you want a JavaScript function to obtain data from server-side, you use AJAX calls to a PHP page that outputs the data for the AJAX to receive. Quote Link to comment https://forums.phpfreaks.com/topic/173176-how-to-call-this-variablehelp-please/#findComment-912885 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.