I'm using the jQuery file uploader plugin along with rails 3. Plugin here:
https://github.com/blueimp/jQuery-File-Upload
I'm using the plugin to allow a user to upload a profile photo. The solution so far works with Chrome, Safari and Firefox. However on IE it fails. When you select a file in IE, the plugin posts to the server but there are no params, it's an empty post.
Example post in chrome:
Started PUT "/api/1/settings/ajax_photo_upload" for 10.0.1.3 at 2012-10-02 15:39:20 -0700
Processing by ApiV1::SettingsController#ajax_photo_upload as JS
Parameters: {"photo"=>#<ActionDispatch::Http::UploadedFile:0x007f9e4bac2e48 #original_filename="xxxxx.jpeg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"user[photo]\"; filename=\"xxxxx.jpeg\"\r\nContent-Type: image/jpeg\r\n", #tempfile=#<File:/var/folders/3x/k1yb0r4s07q1jm82kq93ch180000gn/T/RackMultipart20121002-3633-sxsbtu>>}, "update_type"=>"general"}
However in IE9, it doesn't send over anything:
Started PUT "/api/1/settings/ajax_photo_upload" for 10.0.1.10 at 2012-10-02 15:39:31 -0700
Processing by ApiV1::SettingsController#ajax_photo_upload as JS
Here is my implementation:
$('input[type="file"]').fileupload({
url : '/api/1/settings/ajax_photo_upload',
formData : [{
name : 'authenticity_token',
value : $('meta[name="csrf-token"]').attr('content')
}],
type : 'PUT',
dataType: 'json',
add : function (e, data) {
data.submit();
}
});
html
<input name="user[photo]" type="file" accept="image/*" >
Any ideas why IE would be doing this? Thanks
Are you using the basic plugin? I was and I had the same issue and battled with it for a day only to realize I hadn't included the jquery.iframe-transport.js plugin:
<script src="js/jquery.iframe-transport.js"></script>
See documentation here.
Oh! and thanks for your snippet about including the 'authenticity_token' key-value pair as 'formData' - that helped me get rid of the rails 3 warning "WARNING: Can't verify CSRF token authenticity"
It is basically about the support of html 5's data tags. IE9 has serious problems with it. For example, when you upload an image, in chrome it sents data:blob and gives you the preview before you upload the image actually. In IE, you can't. Check Gmail's mail attachment screen in IE9 you will see the difference. If it is a large scale project, I advise you to use flash as image uploader.
$("#txt1").fileupload({
replaceFileInput: false,
dataType: "json",
datatype:"json",
url: "<%=Page.ResolveUrl("~/WebService/AddAttachment.ashx")%>",
done: function (e, data) {
$.each(data.result, function (index, value) {
//You get the response data in here from your web service
})
$("#txt1").val("");
}`enter code here`
});
This is tested and working fine in both IE8 and IE9 + above. Please make sure to use the correct dataType:"json" (or datatype:"json") and also make sure your response of web service method is correctly updated to data.result when you debug and check.
Thanks
Related
I am testing the adobe document cloud view sdk on https://www.thacherandrye.com/dinner , https://www.thacherandrye.com/the-shed , https://www.thacherandrye.com/brunch
Sometimes, the file preview is not working and all I can get on the screen is a large white space(No errors in the console). Whenever I load the page for the first time, in a browser or incognito window, the file appears on the preview but after reloading or moving to another page with a preview, the file seems to disappear.
I checked for the key being wrong/expired but then it should not have loaded the file even for the first time.
Below is the Javascript code I am using for the api:
$(document).ready(function() {
document.addEventListener("adobe_dc_view_sdk.ready", function(){
var adobeDCView = new AdobeDC.View({ clientId: SOME_KEY, divId: $('#adobeDcViewId{Id}').val() });
adobeDCView.previewFile({
content: { location: { url: $('#hdnUrl{Id}').val() } },
metaData: { fileName: $('#hdnFileName{Id}').val() }
},
{
showDownloadPDF: $('#hdnRestrictDownload{Id}').val() !== 'true',
showPrintPDF: $('#hdnRestrictDownload{Id}').val() !== 'true'
});
});
});
Tech stack: .net framework 4.7.2, jQuery 3.6.0
I tried to help you on our forums, but I don't know if you saw my response. This line worries me:
$('#adobeDcViewId{Id}').val()
The value that needs to be passed to divId needs to be a string, and needs to match the ID of the div element. Also, #adobeDcViewId{Id} doesn't look like a valid CSS selector to me.
Can you try changing this to a hard-coded value of the div on your site?
I've written a javascript uploader which takes images and uploads them to a server. I've stripped the code down to the bare minimum I can, but I still get a leak in Firefox, and I can't see why.
The script obtains a list of file objects called files from a HTML form and then incrementally runs through that list and uploads each file to a server.
The javascript code is as follows:
function UploadFile(file) {
var form_data = new FormData();
form_data.append('file', file);
$.ajax({
url: 'Upload.php',
dataType: 'text',
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function(){
console.log("SUCCESS!");
upload_counter = upload_counter + 1;
UploadFile(files[upload_counter]); //Self calling function
form_data = null; //Clearing form data memory
file = null;
},
error: function(error)
{
console.log("ERROR!");
}
});
}
The function is started again by calling itself from within the success function of the AJAX call, this keeps everything linear and simple, note how it increments along to the next index in the files array to access the next file object.
The PHP code isn't relevant of course, but suffice to say it handles the upload fine.
Using Windows memory monitor the memory used by Firefox is the following:
1 image -> 320Mb
10 images -> 500Mb
20 images -> 720Mb
30 images -> 960Mb
40 images -> 1.1Gb
140 images -> 1.6Gb
150 images -> 1.7Gb
Clearly this is a problem, and eventually Firefox will crash. The files are quite large (around 10Mb each), so by 150 images around 1.5 Gb's have been uploaded.
Why is it leaking memory?
I should add:
this doesn't happen in Chrome, Edge or Opera their memory doesn't change during upload.
I have tested this in Firefox safe mode with all add-ons/extensions disabled as well.
As a result of the fact that it only occurs in Firefox, I've submitted a bug here:
https://bugzilla.mozilla.org/show_bug.cgi?id=1302657
This is just a theory, but it might be a problem with Firefox not hanlding correctly the recursivity of your ajax calls. Since it keeps uploading files again and again, it might not be freeing the memory until it finishes and if you end up consuming all the memory before that, then it will crash.
I think that it might be worth to try something like this:
for(var i=0;i<file.length;i++){
UploadFile(files[i]);
}
And in your UploadFile function, get rid of these 2 lines:
upload_counter = upload_counter + 1;
UploadFile(files[upload_counter]); //Self calling function
Since the "for loop" will already take care of iterate through the files, and with that, you will remove the recursivity in your success callback function.
You might be worried because doing it like that will make the file upload completely asynchronous and it might end up consuming more memory, but since most web browsers limit the number of parallel HTTP requests to up to 6 connections, then based on your benchmarks, you will never be using more than 500MB of RAM (assuming that this approach works for you).
It took me days to stumble on this answer.
The problem/bug lies entirely with firebug, the commonly used developer tool plugin. With it disabled, Firefox actually manages the memory fine.
The code works fine in Firefox but not in IE. I have done a lots of research, but still couldn't find solution.
This function is called from a button on coldfusion cfc file to allow users manually update a report status. I can exactly get what I want in FF, but it doesn't work in IE. I added the alert message to debug the problems. I could get 'Review Status 1', but not 'Review Status 2'. The error form IE is "The object doesn't support this property or method.".
function updateReviewStatus(rowNum) {
alert ("Review Status 1");
var strlen= $("locFund_"+rowNum).innerHTML.split("-")[0].trim().length;
alert("Review status 2");
$("cerStatus_"+rowNum).update("Review Recommended");
$("cerStatus_"+rowNum).style.color="green";
$("cerStatus_Bn_"+rowNum).hide();
new Ajax.Request("?method=updateUIReviewDB",
{
parameters: {
FiscalYear: $("fyfp_"+rowNum).innerHTML.substr(0,4),
FiscalPeriod : $("fyfp_"+rowNum).innerHTML.substr(4,2),
PIUniversalID : "#JSStringFormat(Arguments.PIUniversalID)#",
OPLocCode : $("locFund_"+rowNum).innerHTML.split("-")[0].trim().substr(strlen-1,1),
OPFund : $("locFund_"+rowNum).innerHTML.split("-")[1].trim()
},
method: "post"
});
}
var strlen= $("locFund_"+rowNum).innerHTML.split("-")[0].trim().length;
IE actually has trim() for strings? try
var strlen= $("locFund_"+rowNum).innerHTML.split("-")[0].strip().length;
I'm having an issue where I have deleted code that called an ajax request & displayed a message box in a grid but it is still showing in the browser.
Someone else tried it and it's showing the change for them.
I am using Eclipse & cleaned, rebuilt, removed/readded & restarted my project. I have also cleared all cache/browser hsitory from my browser & tried removing & readding the file to project. None of which have resolved the issue.
The function is being called from an image hyperlink which is being displayed in the grid. That code has not changed, only the underlying function.
This is the actual code in the file:
function getReport(type, date){
alert(type);
alert(date);
}
This is the code shown in Firebug:
function getReport(type, date){
alert(type);
alert(date);
Ext.Ajax.request({
url: 'cxf/rest/ws/getX',
method: 'POST',
timeout:180000,
params: {Type: type, Date: date},
success: function(){
var grid = Ext.getCmp('oGrid');
grid.getStore().reload();
},
failure: function(){
alert('Unable to retrieve the report. Please contact the System Administrator');
}
});
}
Any ideas why this is happening? I have the same setup as the other person who tried it & this is the first time any JS changes have not appeared.
Did you clear your cache? Is there a proxy cache in play?
Open up firebug and see where the code is on the js files. Add break points and see what is called. Track down the problem.
Use fiddler to see the http requests if needed.
In Firebug, open the Firebug menu (top left, picture of a fiery bug) and select "Deactivate Firebug for this site". This is different in some special way from just closing Firebug, which I see you've already done.
I'm trying to make an AJAX call to CouchDB with Qooxdoo, but as far as I can tell no events seem to be firing on my request object (ie. Nothing is appearing on the console and no alerts are coming up). Can anyone tell me what should be happening/what I'm doing wrong?
(This is all in the 'main' method of my class)
var req = new qx.io.remote.Request('http://localhost:5984/japanese/words', 'GET', 'application/json').set({crossDomain:true,timeout:0});
this.debug("Testing");
req.addListener("created", function(e) {
this.debug("Created");
alert(e.getContent());
}, this);
req.addListener("sending", function(e) {
this.debug("Configured");
alert(e.getContent());
}, this);
...
(This is just a sample - I've added a similar listener for all the events I can think of but nothing is coming up on the console)
My server is running Ubuntu 10.10 with Qooxdoo 1.3.
Edit:
Now trying to request "http://localhost/languages/test.php" (my app is at "http://localhost/languages/index.html") and still no alerts are appearing except for the test one I put outside of any event. My request is now: new qx.io.remote.Request('http://localhost/languages/test.php', 'GET', 'application/json'); The PHP file is returning valid JSON when I access it in my browser. Surely this should work?
Cross-domain requests in qooxdoo use a script transport which doesn't fire events. Instead, your server needs to wrap the response data in a call to a static method. See the package documentation of qx.io.remote for details:
http://demo.qooxdoo.org/current/apiviewer/#qx.io.remote