views:

95

answers:

1

... in the context of one element I need to check?

I never faced the problem of uploading using iframe without jQuery, but now I think about uploading from ajax callback which contains a form, an iframe:

<form enctype="multipart/form-data" action="get.imageupload.php" id="upload_form" method="post">
    <input name="userfile" type="file" id="file" />
    <input type="submit" name="action" value="start" />
    <input type="hidden" name="id" value="<?=$id;?>" />
    <iframe id="upload_target" name="upload_target" src="" style="width:0;height:0;border:0"></iframe>
</form>

and the following js:

$("#upload_form").submit(function() {
    $(this).attr("target","upload_target");
    $("iframe", this).load(function() {
        var ret = $("iframe", "#upload_form").contents().find("body").html();
        var data = eval("("+ret+")");
        if (data.success) alert("success"); // todo
        if (data.failure) alert("fail");    // todo
    });
    return false;
});

I have to handle a request from get.imageupload.php that returns JSON data, therefore js looks like that. The problem is: load(fn) doesn't work; ready(fn) instead does, but iframe is empty, because an event fires before the uploading starts... I'm newbie in jQuery and maybe there is another way?

Any ideas?

Thanx

+1  A: 

I don't see why you would use a iframe instead of a div or something similar to load in all the content.

The idea is to load the data in to some element asynchronous.

I would suggest you insert a submit button as well so you have a event to start doing whatever you wanna do. Thats a lightweight and easy way of do a "AJAX Upload".

Hope this was to any help.

Josua Pedersen
`load(fn)` - a function to bind to the load event on each of the matched elements and runs when the page is fully loaded. I'm using this function because I have to hadle the requested json-data. It is not ajax-function
Vov4ik