Welcome Guest! You need to login or register to make posts.



Go to last post Go to first unread
#1 Posted : Monday, July 11, 2011 1:09:54 PM(UTC)

Rank: Newbie

Groups: Member
Joined: 9/8/2009(UTC)
Posts: 2

Hi there,

I am currently using ImageUploader 6.x in a PHP page that I'm working on. I do all of the configuration in PHP including attaching a JS method ("setupUploadUrl") to the "BeforeUpload" event.

setupUploadUrl, my custom JS method, uses an AJAX call to determine what URL the ImageUploader should send its files to, and then from JS, calls "setAction." My issue is that the setAction doesn't seem to take effect until the second time that I click "Upload" on my ImageUploader window pane. The first time I click it tries to POST it to the default which I set in the PHP above. How should I go about setting a default action and then changing it in the JavaScript JUST before upload (the reason that I need to wait until this moment is that the new Action is a function of the number of files that the user is uploading).






<?php $imageUploader->addClientBeforeUpload("setupUploadUrl"); ?>
<script type="text/javascript">
function setupUploadUrl() {
	//get file count
	var numFiles = getImageUploader("ImageUploader1").getUploadFileCount();
	//get upload url
		type:	"POST",
		url:	"asset_locker_get_upload_url.php",
		data:	{"numFiles": numFiles, "as_batch": 1},
		success: function( ret ) {
			if (ret.error) { //error
				return false;
			} else { //default handling
			return true;
		dataType: "json"
	return false;

Thanks a lot!

#2 Posted : Monday, July 11, 2011 9:14:29 PM(UTC)

Rank: Advanced Member

Groups: Member
Joined: 6/16/2009(UTC)
Posts: 134

Was thanked: 8 time(s) in 8 post(s)

The problem is with your ajax call. By default it is asynchronous, so the setupUploadUrl function returns before the ajax call finished and success callback executed.

You can try to make a synchronous call by settings async option to false.

Here is a quote from jQuery documentation:


Default: true

By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active.

Another option is to hide the standard Upload button and make custom html button. When user clicks on that button you make ajax call, set ActionUrl parameter and after that start upload with getImageUploader("ImageUploader1").Send(); method.

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.