By the way, I inserted an error object to AJAX request and I keep getting (object Object) as a response from JSON.
Ajax upload, PHP script example
(60 posts) Great offers for webmaster, blogger and web developer!-
Posted 1 year ago #
-
bt, please open a new thread for your questions and please provide us with an URL
Posted 1 year ago # -
Olaf
This is running on my local machine so I do not have a URL.
Here is the latest of my script which I saved as upload.js. As you will see, I added an error condition to AJAX request.
$(document).ready(function() { $("#loading") .ajaxStart(function(){ $(this).show(); }) .ajaxComplete(function(){ $(this).hide(); }); var options = { beforeSubmit: showRequest, success: showResponse, url: 'upload4jquery.php', // your upload script dataType: 'json', error: function(msg){ alert( "Houston we have a problem: " + msg ); } }; $('#Form1').submit(function() { document.getElementById('message').innerHTML = ''; $(this).ajaxSubmit(options); return false; }); }); function showRequest(formData, jqForm, options) { var fileToUploadValue = document.getElementById('fileToUpload').value; if (fileToUploadValue=="") { document.getElementById('message').innerHTML = '<img src="images/warning.jpeg" width="15 height="15" /><font color="red"> Please select a file.</font>'; return false; } return true; } function showResponse(data, statusText) { if (statusText== 'success') { if (data.img!= '') { document.getElementById('result').innerHTML = '<img src="upload/thumb/'+data.img+'" />'; document.getElementById('message').innerHTML = data.error; } else { document.getElementById('message').innerHTML = data.error; } } else { document.getElementById('message').innerHTML = 'Unknown error!'; } /*document.getElementById('message').innerHTML = 'here is what I got';*/ }I may send you an email, If you would like more info
Posted 1 year ago # -
Hi!
I tried to install on my localhost and on a live server, but i have encountered the same error.
When i try to submit a file, the screen just gives a blink...
Firebug says this after the submit, but disappears very quickly and demands enctype :[Exception... "'Syntax error, unrecognized expression: [@name=fileToUpload]' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "<unknown>" data: no]
Please check out my live test site
Thanks in advance,
scubiPosted 1 year ago # -
Hi,
do you tried the upload script without using ajax?
Posted 1 year ago # -
Yes, it works fine. Upload demo
Posted 1 year ago # -
No I meant the upload script which is used with ajax upload (just upload with form with ajax disabled)
Posted 1 year ago # -
The upload works even in ajax version. The problem is that I don't receive any response. Nor the image or error message. Without ajax everything is fine.
I found in the forum that someone has the same error.Posted 1 year ago # -
strange, I use the same code on my demo page:
http://www.finalwebsites.com/demos/php_ajax_upload_example.phpdo you noticed any difference between both scripts?
Posted 1 year ago # -
I started from the beginning using your scripts.
And the reason why I can't get message and the uploaded picture is :
Permission denied to call method Location.toString
It has to do something with the links, hasn't it?
thanks for your time
Posted 1 year ago #
Topic Closed
This topic has been closed to new replies.