You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Chris Papagrigoriou (JIRA)" <ji...@apache.org> on 2012/06/01 20:52:23 UTC

[jira] [Created] (SLING-2499) File Upload with Ajax using the .ajaxForm() Method doesnt work properly

Chris Papagrigoriou created SLING-2499:
------------------------------------------

             Summary: File Upload with Ajax using the .ajaxForm() Method doesnt work properly
                 Key: SLING-2499
                 URL: https://issues.apache.org/jira/browse/SLING-2499
             Project: Sling
          Issue Type: Bug
          Components: JCR
         Environment: Xubuntu Sling 6
            Reporter: Chris Papagrigoriou
            Priority: Critical


The Form: 
<form  id="fileUploadForm" action="/content/public/instances" method="POST" enctype="multipart/form-data">
<p><input type="file" name="" id="file" /></p>
<p><input type="submit" name="upload" id="uploadButton" /></p>
</form>
The JavaScript:
$(document).ready(function() {

	$("#fileUploadForm").ajaxForm({
		delegation : true,
		
		beforeSubmit : function() {
			var fileName = $('#file').val();
			fileName = fileName.replace("C:\\fakepath\\", "");

			$('#file').attr("name", fileName);
		},
		
		success : function() {
			alert("SUCCESS!");
		}
		
	});	
	
});

It works only, if press the submit button twice. At the first click he doesn't create anything. After the second click he uploads the file into /content/public/instances/<filename>

I tested it with a normal form. Seems I get this problem only when I try to upload the file with ajax.


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (SLING-2499) File Upload with Ajax using the .ajaxForm() Method doesnt work properly

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SLING-2499?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13287746#comment-13287746 ] 

Felix Meschberger commented on SLING-2499:
------------------------------------------

So, you have to click twice: Does this cause two requests ? Or is the Ajax request only sent with the second click ?

If it is only sent with the second click, this has something to do with your client-side form setup.
                
> File Upload with Ajax using the .ajaxForm() Method doesnt work properly
> -----------------------------------------------------------------------
>
>                 Key: SLING-2499
>                 URL: https://issues.apache.org/jira/browse/SLING-2499
>             Project: Sling
>          Issue Type: Bug
>          Components: JCR
>         Environment: Xubuntu Sling 6
>            Reporter: Chris Papagrigoriou
>            Priority: Critical
>
> The Form: 
> <form  id="fileUploadForm" action="/content/public/instances" method="POST" enctype="multipart/form-data">
> <p><input type="file" name="" id="file" /></p>
> <p><input type="submit" name="upload" id="uploadButton" /></p>
> </form>
> The JavaScript:
> $(document).ready(function() {
> 	$("#fileUploadForm").ajaxForm({
> 		delegation : true,
> 		
> 		beforeSubmit : function() {
> 			var fileName = $('#file').val();
> 			fileName = fileName.replace("C:\\fakepath\\", "");
> 			$('#file').attr("name", fileName);
> 		},
> 		
> 		success : function() {
> 			alert("SUCCESS!");
> 		}
> 		
> 	});	
> 	
> });
> It works only, if press the submit button twice. At the first click he doesn't create anything. After the second click he uploads the file into /content/public/instances/<filename>
> I tested it with a normal form. Seems I get this problem only when I try to upload the file with ajax.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (SLING-2499) File Upload with Ajax using the .ajaxForm() Method doesnt work properly

Posted by "Chris Papagrigoriou (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SLING-2499?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13287767#comment-13287767 ] 

Chris Papagrigoriou commented on SLING-2499:
--------------------------------------------

It causes two requests.

Response 1: 
Content modified /content/public/instances
Status 	
200
Message 	
OK
Location 	/public/instances
Parent Location 	/public
Path 	
/content/public/instances
Referer 	http://localhost:8080/index.html
ChangeLog

Response2:
Content modified /content/public/instances
Status 	
200
Message 	
OK
Location 	/public/instances
Parent Location 	/public
Path 	
/content/public/instances
Referer 	http://localhost:8080/index.html
ChangeLog 	

created("/content/public/instances/formula.cnf");
created("/content/public/instances/formula.cnf/jcr:content");
modified("/content/public/instances/formula.cnf/jcr:content/jcr:lastModified");
modified("/content/public/instances/formula.cnf/jcr:content/jcr:mimeType");
modified("/content/public/instances/formula.cnf/jcr:content/jcr:data");

Now the file was actually uploaded. It doesn't make any sense.

                
> File Upload with Ajax using the .ajaxForm() Method doesnt work properly
> -----------------------------------------------------------------------
>
>                 Key: SLING-2499
>                 URL: https://issues.apache.org/jira/browse/SLING-2499
>             Project: Sling
>          Issue Type: Bug
>          Components: JCR
>         Environment: Xubuntu Sling 6
>            Reporter: Chris Papagrigoriou
>            Priority: Critical
>
> The Form: 
> <form  id="fileUploadForm" action="/content/public/instances" method="POST" enctype="multipart/form-data">
> <p><input type="file" name="" id="file" /></p>
> <p><input type="submit" name="upload" id="uploadButton" /></p>
> </form>
> The JavaScript:
> $(document).ready(function() {
> 	$("#fileUploadForm").ajaxForm({
> 		delegation : true,
> 		
> 		beforeSubmit : function() {
> 			var fileName = $('#file').val();
> 			fileName = fileName.replace("C:\\fakepath\\", "");
> 			$('#file').attr("name", fileName);
> 		},
> 		
> 		success : function() {
> 			alert("SUCCESS!");
> 		}
> 		
> 	});	
> 	
> });
> It works only, if press the submit button twice. At the first click he doesn't create anything. After the second click he uploads the file into /content/public/instances/<filename>
> I tested it with a normal form. Seems I get this problem only when I try to upload the file with ajax.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (SLING-2499) File Upload with Ajax using the .ajaxForm() Method doesnt work properly

Posted by "Carsten Ziegeler (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SLING-2499?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Carsten Ziegeler updated SLING-2499:
------------------------------------

    Priority: Minor  (was: Critical)
    
> File Upload with Ajax using the .ajaxForm() Method doesnt work properly
> -----------------------------------------------------------------------
>
>                 Key: SLING-2499
>                 URL: https://issues.apache.org/jira/browse/SLING-2499
>             Project: Sling
>          Issue Type: Bug
>          Components: JCR
>         Environment: Xubuntu Sling 6
>            Reporter: Chris Papagrigoriou
>            Priority: Minor
>
> The Form: 
> <form  id="fileUploadForm" action="/content/public/instances" method="POST" enctype="multipart/form-data">
> <p><input type="file" name="" id="file" /></p>
> <p><input type="submit" name="upload" id="uploadButton" /></p>
> </form>
> The JavaScript:
> $(document).ready(function() {
> 	$("#fileUploadForm").ajaxForm({
> 		delegation : true,
> 		
> 		beforeSubmit : function() {
> 			var fileName = $('#file').val();
> 			fileName = fileName.replace("C:\\fakepath\\", "");
> 			$('#file').attr("name", fileName);
> 		},
> 		
> 		success : function() {
> 			alert("SUCCESS!");
> 		}
> 		
> 	});	
> 	
> });
> It works only, if press the submit button twice. At the first click he doesn't create anything. After the second click he uploads the file into /content/public/instances/<filename>
> I tested it with a normal form. Seems I get this problem only when I try to upload the file with ajax.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (SLING-2499) File Upload with Ajax using the .ajaxForm() Method doesnt work properly

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SLING-2499?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13287677#comment-13287677 ] 

Felix Meschberger commented on SLING-2499:
------------------------------------------

Are you sure this is not a problem of your beforeSubmit method: This should return a boolean indicating whether to continue or not.
                
> File Upload with Ajax using the .ajaxForm() Method doesnt work properly
> -----------------------------------------------------------------------
>
>                 Key: SLING-2499
>                 URL: https://issues.apache.org/jira/browse/SLING-2499
>             Project: Sling
>          Issue Type: Bug
>          Components: JCR
>         Environment: Xubuntu Sling 6
>            Reporter: Chris Papagrigoriou
>            Priority: Critical
>
> The Form: 
> <form  id="fileUploadForm" action="/content/public/instances" method="POST" enctype="multipart/form-data">
> <p><input type="file" name="" id="file" /></p>
> <p><input type="submit" name="upload" id="uploadButton" /></p>
> </form>
> The JavaScript:
> $(document).ready(function() {
> 	$("#fileUploadForm").ajaxForm({
> 		delegation : true,
> 		
> 		beforeSubmit : function() {
> 			var fileName = $('#file').val();
> 			fileName = fileName.replace("C:\\fakepath\\", "");
> 			$('#file').attr("name", fileName);
> 		},
> 		
> 		success : function() {
> 			alert("SUCCESS!");
> 		}
> 		
> 	});	
> 	
> });
> It works only, if press the submit button twice. At the first click he doesn't create anything. After the second click he uploads the file into /content/public/instances/<filename>
> I tested it with a normal form. Seems I get this problem only when I try to upload the file with ajax.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (SLING-2499) File Upload with Ajax using the .ajaxForm() Method doesnt work properly

Posted by "Chris Papagrigoriou (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SLING-2499?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13287737#comment-13287737 ] 

Chris Papagrigoriou commented on SLING-2499:
--------------------------------------------

Hey Felix,

thank you for the help. That doesn't seem to solve the issue, besides you only need to return false, if you want to cancel the submission. Got that from: http://jquery.malsup.com/form/#options-object

"beforeSubmit
Callback function to be invoked before the form is submitted. The 'beforeSubmit' callback can be provided as a hook for running pre-submit logic or for validating the form data. If the 'beforeSubmit' callback returns false then the form will not be submitted. The 'beforeSubmit' callback is invoked with three arguments: the form data in array format, the jQuery object for the form, and the Options Object passed into ajaxForm/ajaxSubmit."
                
> File Upload with Ajax using the .ajaxForm() Method doesnt work properly
> -----------------------------------------------------------------------
>
>                 Key: SLING-2499
>                 URL: https://issues.apache.org/jira/browse/SLING-2499
>             Project: Sling
>          Issue Type: Bug
>          Components: JCR
>         Environment: Xubuntu Sling 6
>            Reporter: Chris Papagrigoriou
>            Priority: Critical
>
> The Form: 
> <form  id="fileUploadForm" action="/content/public/instances" method="POST" enctype="multipart/form-data">
> <p><input type="file" name="" id="file" /></p>
> <p><input type="submit" name="upload" id="uploadButton" /></p>
> </form>
> The JavaScript:
> $(document).ready(function() {
> 	$("#fileUploadForm").ajaxForm({
> 		delegation : true,
> 		
> 		beforeSubmit : function() {
> 			var fileName = $('#file').val();
> 			fileName = fileName.replace("C:\\fakepath\\", "");
> 			$('#file').attr("name", fileName);
> 		},
> 		
> 		success : function() {
> 			alert("SUCCESS!");
> 		}
> 		
> 	});	
> 	
> });
> It works only, if press the submit button twice. At the first click he doesn't create anything. After the second click he uploads the file into /content/public/instances/<filename>
> I tested it with a normal form. Seems I get this problem only when I try to upload the file with ajax.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira