#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    5
    Rep Power
    0

    Question How can i print out information from a js file to an html file?


    Hi i'm not going to print out all the code, but some of it, so you hopefully will understand

    i'm running a function in javascript that is sending some information to a php file.


    Code:
    function verify_oload(){
            if (xmlHttp.readyState == 0 || xmlHttp.readyState == 4) {
                        var queryString = "id_user=1&name=name";
                        xmlHttp.open("GET", "code/php/core.php?" + queryString, true);
                        xmlHttp.onreadystatechange = handleServerRespons_vo;
                        xmlHttp.send();
               }else{
               setTimeout('whovisit()', 1000)
           }  
    }
    this is not the real php file, but it describes what i want it to do.

    PHP Code:
    header('Content-Type: text/xml');
    echo '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>';
    echo '<response>'; 
    $name = $_GET['name'];
    $id_user = $_GET['id_user'];

    echo'<p>'.$name.'</p><h1>'.$id_user.'</h1>';

    echo '</response>';
    Here the javascript get the information from the php code

    Code:
    function handleServerRespons_vo(){
      
        if (xmlHttp.readyState == 4){
            
            if (xmlHttp.status == 200){
                var xmlResponse = xmlHttp.responseXML;
                var xmlDocumentElement = xmlResponse.documentElement;
                var message = xmlDocumentElement.firstChild.data;
                alert(message);
                    verify_onload.outerHTML = message ;
                    }
                }
            }
    This is how i print it out on the screen, but nothing happends, and an error pops up. But why? And is it other ways to do this?

    Code:
    <div id="verify_onload" ></div>
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,165
    Rep Power
    184
    Why are you using HTML tags, in your XML; without CDATA?

    Your also using a self closing tag. with your #verify_onload div; that could be one problem there:
    Code:
    <div id="verify_onload" />
    This tutorial, may also be helpful to you: http://www.javascriptkit.com/dhtmltu...getpost3.shtml

    Also, what specific error; are you receiving in your browser's developer's console?
    Last edited by web_loone08; June 26th, 2013 at 09:13 PM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    5
    Rep Power
    0
    Ah, i understand now ty

IMN logo majestic logo threadwatch logo seochat tools logo