Page 1 of 1
Using Ajax to get HTML total results
Posted: Sat Feb 17, 2007 5:00 am
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
Posted: Sat Feb 17, 2007 6:54 am
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.
Ajax + js code
Posted: Sat Feb 17, 2007 9:09 am
by mbaroz
Hi
so Should i write in the server side :
Code: Select all
<script language=javascript>var numrows=<?=222;?>;</script>
?
Posted: Sat Feb 17, 2007 10:08 am
by superdezign
Yes.
Ajax + js code
Posted: Sat Feb 17, 2007 11:07 am
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:
and it returns undefined.
any suggestion ?
Thanks again
Moshe
Posted: Sat Feb 17, 2007 11:13 am
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.
Ajax + js code
Posted: Sat Feb 17, 2007 2:14 pm
by mbaroz
hi
Sorry i dont know which part to put in the client side code and which in the serverside code ?
Thanks
Moshe
Posted: Sat Feb 17, 2007 3:04 pm
by nickvd
Did you read the page I linked?