Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

php and ajax problem

 
Alexandru Gifei
Ranch Hand
Posts: 42
Java Linux Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I have the following script where i receive a message from a http client and return it as a string.


In this last script i am using Ajax to get the $lastLine string from status.php, and display the content in it's div containter, but i want to split $lastLine by spaces, into an array, and use ajax to populate the page with the values of this array because i want to use them later to build a html table. So the question is HOW can i use ajax to load the data from the array into the variables into $btStatus, $maxTemp, $minTemp, $currentTemp, and use them later? or HOW can i get the string that is displayed in the div container and use it later?

Edit: I came up with a solution, to build the html table in status.php and echo it with ajax in the div container. But im looking for a better solution ;)
 
Clivant Yeo
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess I will just let status.php output the required data without any formatting, which could be JSON or csv format.

Then I will use jQuery/javascript to load the data into some variables which I will manipulate and do the formatting.

This is because, the visual aspect of an application tends to change more then server side counterpart. By pushing the formatting job to the javascript side, you will only need to make any visual changes in one file. But if you were to let your server end output the visual information, you will need to change the data in more places.

But of course to cater to cases in which Javascript is disabled, I will have another PHP file which will provide for the visual aspect. And I will group the file under a same folder as index.php, so that when I need to change the visual part, I will not need to look too far.

Just my 2 cents though.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic