SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question ResponceText prints out include js.php doesn't run the external.js?

    Hello gang,
    I've been struggling for a week to get the Ajax called elements to run the external.js file script. I used get elementbyid to place an src on a blank script tag with a function that calls the Ajax call that works and alters the innerHTML of the correct div on my index.html but can't run the js on those new well styled elements unless I hardcode the events into the get.php? So I tried creating an include 'js.php' at the bottom of the get.php but only resulted in the js.php being printed out at the bottom of the responceText. Can anybody tell me if the UniServer php INI needs to be adjusted to parse js.php files differently in order to run javascript on responceText html elements? Or do I have to hard code/inline the events on the get.php file. Which does seem to work but is nonobtrusive to say the least? Any comments greatly appreciated.

  2. #2
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb RESOLVED!!!ResponceText prints out include js.php doesn't run the external.js?

    Ok. apparently there is no other way than to hard code the events into the get.php file like so:
    get.php
    PHP Code:
    //should have fetch_as_array statement to hold new html data in memory
    echo "<img src='" $row['src'] . "' class='image' onclick='pictureclick()' title='Click to get a better look'/></div>"
    The 'OnClick' function is 'Hard Coded/Writen in-line of the HTML requested. As there is no window reload required by the Ajax call the function that makes the Ajax call actually writes the 'src' of a script tag with getelementbyid script tag id . This prevents appending or writing 10 or more of the same script tag to the document. If you force window reload the responceText HTML will disapear so the new script will draw errors like 'object not found/object expected'. The responceText HTML has to be hardcoded to run the new external.js!
    Add external.js with Ajax call
    Code:
    document.getElementById('blank').src='scripts/checkout.js';
    };
    index.html
    HTML Code:
    <script id="blank" src="" type="text/javascript"></script>
    Which makes me question why we decided to use 'Unobtrussive or External.js' in the first place as it actually adds a third step to comunicating with the server. The answer of course is security as this method doesn't reveal the script src in the original page source code! Not that a hacker won't look for it in the script file that is revealed. That becomes his only recourse and is an additional means of security.


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
  •