XUpload - JS call instead of redirect?

Message
Author
perejunk
Posts: 2
Joined: May 15, 2007 11:56 pm

JS call instead of redirect?

#1 Postby perejunk » May 16, 2007 12:01 am

Hi!

I use the prototype javascript library for my ajax calls... how would I could configure the script to call a js script instead of a redirect after the file has finished uploading?

Pere

User avatar
PilgrimX182
Posts: 2186
Joined: Mar 22, 2006 1:39 pm

#2 Postby PilgrimX182 » May 16, 2007 3:43 am

It is possible.

I guess you're using FREE version. Here goes hack: in upload.cgi replace

Code: Select all

### Sending data with POST request if required
my $url_post = $cg->param('url_post');
$url_post ||= $c->{url_post};
if($url_post)
{
   my ($str,@har);
   for (0..$#fileslots)
   {
      push @har, { name=>$fileslots[$_],          'value'=>$filenames[$_] };
      push @har, { name=>"$fileslots[$_]_status", 'value'=>$file_status[$_] };
   }
   for my $k (@params)
   {
      my @arr = $cg->param($k);
      for my $p (@arr)
      {
         next if ref $p eq 'Fh'; #&& $p !~ /\.$c->{ext_allowed}$/i; # Skip unallowed files
         $p =~ s/.*\\([^\\]*)$/$1/;
         push @har, { name=>$k, value=>$p };
      }
   }

   push @har, { name=>'target_dir', value=>$c->{target_dir} };

   print"<HTML><BODY onLoad='document.F1.submit();'><Form name='F1' action='$url_post' target='_parent' method='POST'>";
   print"<textarea name='$_->{name}'>$_->{value}</textarea>" for @har;
   print"</Form></BODY></HTML>";
   exit;
}

### Upload finished, redirecting 
my $redirect_link = $cg->param('redirect_link');
$redirect_link ||= $c->{redirect_link};
print"<HTML><Script>parent.document.location='$redirect_link';</Script></HTML>";
with

Code: Select all

print"<HTML><Script>parent.YOURJSFUNCTION();</Script></HTML>";
haven't tested something like this, but should work.

perejunk
Posts: 2
Joined: May 15, 2007 11:56 pm

#3 Postby perejunk » May 16, 2007 6:23 am

Actually, I am using the Pro version... I just purchased it today. Will this same method work for the Pro version?

By the way, I am amazed by the quality and timeliness of your responses in this forum.

Thanks again,

Peregrin

User avatar
PilgrimX182
Posts: 2186
Joined: Mar 22, 2006 1:39 pm

#4 Postby PilgrimX182 » May 16, 2007 1:25 pm

Thanks!

In Pro version you need to replace

Code: Select all

### Sending data with POST request if need
.......
print"Content-type: text/html\n\n";
print"Upload complete.";
with

Code: Select all

print"Content-type: text/html\n\n";
print"<HTML><Script>parent.YOURJSFUNCTION();</Script></HTML>";