Results 1 to 3 of 3

Thread: accessing php generated HTML from javascript

  1. #1
    Join Date
    Apr 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default accessing php generated HTML from javascript

    I doubt this is possible based on javascript's security blocks, but is there a way to grab the raw HTML that a php script generates (exactly as if you hit 'view source') and access it through javascript (as text - I don't care about the HTML formatting, actually).

    Basically, we've got a web-based order processing system for a graphics department. I'd like to have some local scripts parse the orders for me, but I can't because the HTML is coming from a remote site. Right? (Please tell me I'm wrong.)

    Thanks!
    -Rich

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Well... I don't know exactly how your stuff is setup, but here's a VERY simple way of doing that:

    Note: I don't do JS... command for saving to a variable might be off... I dunno.
    PHP Code:
    <script>
    var = "<?php echo "echoed text that's now equal to 'var'"?>"
    </script>
    So.... in short, just make sure the php (or at least the echo statement) is within the place where a variable gets its value... then use that variable to interpret the stuff later.

    However, you could just as easily (probably more so) make PHP do the interpretation for you, and you'd be done.

    This help?

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    By the way you phrased that question, I don't think this is an acceptable solution. Right?
    There is one very easy way to get around the Javascript security limitations, which is to serve the required page from the same domain. A simple script:
    Code:
    <?php include("http://www.othersite.com/calculateprices.php"); ?>
    You can then access the page using an XMLHttpRequest.
    Code:
          function getHttpRequest() {
            if(typeof ActiveXObject == "undefined" && typeof XMLHttpRequest == "undefined") return null;
            var xmlhttp;
            /*@cc_on
              @if (@_jscript_version >= 5)
                try xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                catch (e) {
                  try xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                  catch (E) xmlhttp = false;
                }
    	  @else xmlhttp = null;
    	@end @*/
    
            if (xmlhttp == null && typeof XMLHttpRequest != 'undefined') {
              try {
                xmlhttp = new XMLHttpRequest();
              } catch (e) {
                xmlhttp = null;
              }
            }
            return xmlhttp;
          }
    
    // ...
          function getPHPOutput() {
            (var xh = getHttpRequest()) == null ? return false : 0;
            xh.open("GET", "getpage.php", false);
            xh.send(null);
            if(xh.readyState != 4) return false;
            else return xh.responseText;
          }
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •