Using Ajax to get HTML total results

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
mbaroz
Forum Commoner
Posts: 29
Joined: Sun Feb 05, 2006 10:10 am

Using Ajax to get HTML total results

Post by mbaroz »

Hi all
I am using xmlHTTP function block to retrieve the innerHTML to a DIV . I also have Paging option to the results.
My problem is to Retrieve the Total num of rows from the Server Side into the INNER DIV NOT As an HTML format .
I need this Num rows number just to let my clientside know how many rows left to show.

How can i implement it ?
Thanks
Moshe
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

You could obtain the total number of rows from the server side script and just add it to the AJAX code, assuming you are using more than just AJAX.

Code: Select all

var numOfRows=<?=$numOfRows?>;
mbaroz
Forum Commoner
Posts: 29
Joined: Sun Feb 05, 2006 10:10 am

Ajax + js code

Post by mbaroz »

Hi
so Should i write in the server side :

Code: Select all

<script language=javascript>var numrows=<?=222;?>;</script> 
?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Yes.
mbaroz
Forum Commoner
Posts: 29
Joined: Sun Feb 05, 2006 10:10 am

Ajax + js code

Post by mbaroz »

Hi
Its not working. let me explain my code again :
I have a main page that user JS function that calls xmlHTTP Object to a URL in server side (server.php)
I need the NumRows to be avaliable in this main file .

in the Server.php file i added :

Code: Select all

print "<script language=javascript>var NumRows=3</script>";
and in the main js script i use:

Code: Select all

alert(NumRows);
and it returns undefined.

any suggestion ?
Thanks again
Moshe
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

The best thing to do is to return a JSON string, which gets eval()'d on the client side (preferably using a javascript based json parser to avoid eval() usage).

The string would be returned as such:

Code: Select all

{
  'myvar' : 'myvalue',
  'text' : 'all your html are belong to us'
}
You would eval() (or parse it) in your callback function.

Code: Select all

eval('var returnData = ' + thedatayoureturned);
You could then access the data.

Code: Select all

alert(returnData.myvar);
mbaroz
Forum Commoner
Posts: 29
Joined: Sun Feb 05, 2006 10:10 am

Ajax + js code

Post by mbaroz »

hi
Sorry i dont know which part to put in the client side code and which in the serverside code ?
Thanks
Moshe
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Did you read the page I linked?
Post Reply