/    Sign up×
Community /Pin to ProfileBookmark

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:

[code]
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.
}
[/code]

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 ?

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@aj_nscDec 03.2010 — 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:
<i>
</i>$('#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.
Copy linkTweet thisAlerts:
@SyncUpSolutionsauthorDec 03.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

test.php?HASH=whatehashisatthetime&reload=whateverpagetoreload

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.
Copy linkTweet thisAlerts:
@aj_nscDec 03.2010 — 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.
Copy linkTweet thisAlerts:
@SyncUpSolutionsauthorDec 03.2010 — lol.

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.
    Copy linkTweet thisAlerts:
    @aj_nscDec 03.2010 — 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.
    ×

    Success!

    Help @SyncUpSolutions spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.20,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...