Results 1 to 6 of 6

Thread: Call function inside of load()

  1. #1
    Join Date
    Dec 2010

    Call function inside of load()

    Hey everyone, long time lurker - first time poster. I'm completely new to Javascript and all of it's clicks and whistles (jQuery, AJAX, etc..). My question is, is it possible to call a function inside of the load event ? I need something to dynamically pull a cookie value each time the function is called. This is what I have:

    function populateParentWindow() {
         $("#FTPContents").load("functions/testftp.php?HASH="+Get_Cookie("User")+"&reload=<?php echo $_SESSION['currentdirectory'];?>");
         return false; // you'll need this to ensure that you don't actually have a clickthrough to your child window link.
    That particular function updates a div after the file has been uploaded. I'm using SWFUpload, I'm sure most of you are familiar with it. I need the HASH to be a cookie value, but the value changes depending on the current directory the user is viewing. Can this be done ?

  2. #2
    Join Date
    Dec 2005
    First of all there's no such thing as a load event - onload is an event. However, I do know that you are referring to the $.load function in the jQuery library.

    Second, that's pretty much what $.load was designed for, a callback function. Check the documentation here -> http://api.jquery.com/load/

    Briefly, this is how it works:
    $('#FTPContents.load(url,dataReturned,function() {
       alert('stuff has been loaded');
    You are mixing php with Javascript, which is a no no, PHP is not javascript and cannot be used like you're using it.

    Good luck.
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...

  3. #3
    Join Date
    Dec 2010
    Well, the PHP works fine inside the javascript. It's probably not good practice, but it does work. The problem that I'm having is that PHP, as you know, is server-side, where javascript is client-side. That particular function needs to update the value of HASH and reload before it is executed. The example you showed me wont do that. It will simply call the page. I need the page to be requested like this


    the hash is stored in a cookie, and so is the reload page.

    Is there anyway to use load() to retreieve the cookies and parse the information where it needs to be in the URL. Thats what I'm trying to accomplish.

  4. #4
    Join Date
    Dec 2005
    What you just said is the definition of PHP and Javascript "not working".

    You don't need to use load to retrieve cookies, you can just use normal Javascript. And that, fortunately, can be done. Cookies can be set using PHP and read using Javascript and vice versa.

    Check out http://www.w3schools.com/js/js_cookies.asp - they've got great code samples that will come in handy.

    Where does the has come from? You're likely going to have to use AJAX.
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...

  5. #5
    Join Date
    Dec 2010

    I'm not javascript expert at all, but I can tell you 100% that you can use PHP echo() inside of javascript and it works swimingly, My problem is that I'm converting from using PHP Sessions, to just cookies. Because one thing you cannot do is update a PHP Session variable with javascript, because Sessions are server-side.

    2 things need to happen here.

    I've just about figured it out, I guess I would just like to explain whats going on.

    I'm creating an web-based FTP manager for my customers, we sell Online Backup. In the account homepage I have 2 DIVS.

    1. FTP Manager, which shows testftp.php
    2. SWFUpload - I'm sure you know what that is.

    Now, pretty much all the ftp manager div is:

    <div id="ftmanager"><?php include('testftp.php'); ?></div>

    So, testftp.php shows the directory for the user, and what this whole operation revolves around is not having to reload the entire page when the user clicks a link to move through his or her folders. Simple enough, I can do that.

    BUT, the problem is. The current directory that there in must be stored somehow so that when they upload from the SWFUpload div, so the script knows which folder to upload to, and which folder to display when reloading the div. hence the .load jquery with the HASH and reload values.

    This could all be avoided if I just reloaded the entire page, but that is a strain on the server to continuously pull the session information and information from the DB, so this is must.

    Hopefully I've explained what I'm looking for a little better. The cookie will change once testftp.php is loaded, but the SWFUPload div never refreshes, so by itself it cannot know the cookie values have updated, which is why I need to call the Get_Cookie function before the actual load happens.

  6. #6
    Join Date
    Dec 2005
    I can tell you with 100&#37; certainty that it doesn't work - not the way you want it to. The only reason it works at all is because you're using the script inline - e.g. hardcoded into the HTML document. If the Javascript src was stored in an external file, then it would not work.

    The reason WHY you think it "works" is because when the page is parsed by the PHP parser, it puts the value of <?php echo $_SESSION['currentdirectory'];?> in where it should be. But you SHOULD not be doing this. The second that file is made an external Javascript file it will break.

    Where does the value of HASH come from? I tried to ask that question in the last post but I mistyped, my mistake.
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10680 seconds
  • Memory Usage 2,891KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates