Jump to content

how to call this variable...help please


rsalumpit

Recommended Posts

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..

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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});
		});
		}


Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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!

 

 

Link to comment
Share on other sites

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.... >.<

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

.. 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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.