Solved

Controlling PHP Output

Posted on 2012-12-21
10
276 Views
Last Modified: 2012-12-22
I'm working on a web page that has a div that contains a slide show.  The source of the page is a database record on the server that contains the  type of slide show, pointers to the images that will be displayed, and perhaps a half dozen other slide show parameters that the user will set through their browser by interacting with a JavaScript dialog. The idea is that the slide show parameters will be Ajaxed up to the server, the server will build the new HTML for the player div, and the new innerHTL for the player div will be Ajaxed back down.

What I'm not seeing clearly is how I can get PHP to build up the player div HTML without outputting anything automatoca;;u to the client.  That is, normally when a browser requests a PHP page, the PHP runs and whatever is left automatically shows up in the client' browser.  I don't want that.  I just want what the innHTML for one div to show up and this only because we return it in a Ajax request.

Thanks for any thought.
Steve
0
Comment
Question by:steva
  • 6
  • 3
10 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 38714922
This is the sort of thing we can do with jQuery.  Have you got any code base yet?  Please show us what you have tried, or what learning resources you've pursued.

Possibly useful:
http://www.amazon.com/Learning-jQuery-Interaction-Development-JavaScript/dp/1847192505
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 38714939
This is also going to be more than one page or file of code.  You need the initial file that displays the main page.  You need a PHP page that responds to the AJAX requests and you need another page that records the user settings in the database.
0
 

Author Comment

by:steva
ID: 38714944
Hi Ray,

There's no code yet.  I'm still walking through the whole thing in my mind.

Regarding jQuery resources, on my bookshelf I have:
   Learning jQuery 1.3 - Swedberg
    jQuery Cookbook - Various Experts
    jQuery in Action - Bibeault & Katz
    Head First jQuery - Benedetti
    jQuery Enlightmenment - Lindley
    Pro jQuery - Freeman

But my question doesn't seem to be about jQuery.  The question is how to make PHP construct just a piece of the page - the slide show div - and return that innereHTML in an Ajax response, without causing anything to display on the client's browser.  What does that PHP script look like?  I'll have no problem getting jQuery on the client page to put that innerHTML in the right place.

Steve
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:steva
ID: 38714947
Dave,

This is also going to be more than one page or file of code.  You need the initial file that displays the main page.  You need a PHP page that responds to the AJAX requests and you need another page that records the user settings in the database.

Agreed.  The question now is what will the PHP script look like that responds to the Ajax request that is passing up the new slide show parameters.  How do I get that script to build the new slide show div and respond to the Ajax request with  the new innerHTML, without displaying anything on the client's browser?

Steve
0
 

Author Comment

by:steva
ID: 38714955
Or maybe the best solution is to build the div with jQuery at the client, rather than bothering PHP, and then upload the new div innerHTML to the server later, to keep it in the loop.  Maybe this is what Ray was suggesting, but I missed it.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 38714957
... return that innereHTML in an Ajax response, without causing anything to display...
Why would you want to return something that causes nothing to display?  I am not getting this concept yet, I think.
0
 

Author Comment

by:steva
ID: 38715008
It will display when the jQuery in the client sticks the Ajax response into the DOM.  I just wanted to avoid doing something in PHP that caused the whole page to go down and get displayed, since that's what normally happens when you request a php page.  That is, you request a php page, php runs, and bang! -  the whole thing in your browser.  But I'm not issuing a browser request for a php page here, so maybe I'm worrying about nothing.

Plus, as I suggested in my last post, the better solution is probably to have jQuery process the new slide show parameters at the client and put the results directly into the div, instead of getting involved with the server at this point.
0
 

Author Closing Comment

by:steva
ID: 38715159
Thanks.  I probably wasn't very clear about what I was trying to do, but in my own mind I'm past the block I had, and I credit the dialog here for getting me past that.  Sometimes you just need to talk to someone.

Thanks
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 38715472
Sounds like you're on the right track.  Usually jQuery can be used to just reload a part of the browser viewport, not the whole web page.
0
 

Author Comment

by:steva
ID: 38716223
I too only wanted to load a part, but that part was the entire innerHTML of a div and I didn't know how to do that without triggering a download of the whole page.  Since I started this post I've decided I probably don't need to  have the server send me a div's html, but if I do return to that approach I discovered phpquery, that I'd never heard of before yesterday.  It apparently will build a DOM on the server for a page and pull out any part of it you want -  just what I was looking for.

Anyway, thanks for your interest.
Steve
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question