Reading a file from html to jquery and then uploading it to ajax [duplicate]
This question already has an answer here:
JQuery: 'Uncaught TypeError: Illegal invocation' at ajax request - several elements
8 answers
JQuery: 'Uncaught TypeError: Illegal invocation' at ajax request
1 answer
submit form with ajax but get “Illegal Invocation”
1 answer
How can I upload files asynchronously?
31 answers
I have an input tag in HTML
<input id="fileId" type="file" name="fileId" style="display:none;">
I need to receive this file object in javascript to pass it in back-end through ajax.
I am using below line to get file object.
var fileObject = $('#fileId').prop('files')[0]
I am able to receive the file object with this line of code.
and my ajax code is:
$.ajax({
type: 'POST',
url: '/urlname/',
data: {"file_object": fileObject},
success: function(data) {
console.log(data)
}
});
I am not able to execute the ajax code since it producing Illegal invocation error while parsing the object through the ajax.
below is the error trace:
jquery.min.js:2 Uncaught TypeError: Illegal invocation
at i (jquery.min.js:2)
at jt (jquery.min.js:2)
at Function.w.param (jquery.min.js:2)
at Function.ajax (jquery.min.js:2)
at HTMLButtonElement.<anonymous> (index.js:36)
at HTMLButtonElement.dispatch (jquery.min.js:2)
at HTMLButtonElement.y.handle (jquery.min.js:2)
i @ jquery.min.js:2
jt @ jquery.min.js:2
w.param @ jquery.min.js:2
ajax @ jquery.min.js:2
(anonymous) @ index.js:36
dispatch @ jquery.min.js:2
y.handle @ jquery.min.js:2
Also, I need to read this file object in Django's views.py.
javascript jquery ajax
marked as duplicate by mplungjan
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 5:59
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
JQuery: 'Uncaught TypeError: Illegal invocation' at ajax request - several elements
8 answers
JQuery: 'Uncaught TypeError: Illegal invocation' at ajax request
1 answer
submit form with ajax but get “Illegal Invocation”
1 answer
How can I upload files asynchronously?
31 answers
I have an input tag in HTML
<input id="fileId" type="file" name="fileId" style="display:none;">
I need to receive this file object in javascript to pass it in back-end through ajax.
I am using below line to get file object.
var fileObject = $('#fileId').prop('files')[0]
I am able to receive the file object with this line of code.
and my ajax code is:
$.ajax({
type: 'POST',
url: '/urlname/',
data: {"file_object": fileObject},
success: function(data) {
console.log(data)
}
});
I am not able to execute the ajax code since it producing Illegal invocation error while parsing the object through the ajax.
below is the error trace:
jquery.min.js:2 Uncaught TypeError: Illegal invocation
at i (jquery.min.js:2)
at jt (jquery.min.js:2)
at Function.w.param (jquery.min.js:2)
at Function.ajax (jquery.min.js:2)
at HTMLButtonElement.<anonymous> (index.js:36)
at HTMLButtonElement.dispatch (jquery.min.js:2)
at HTMLButtonElement.y.handle (jquery.min.js:2)
i @ jquery.min.js:2
jt @ jquery.min.js:2
w.param @ jquery.min.js:2
ajax @ jquery.min.js:2
(anonymous) @ index.js:36
dispatch @ jquery.min.js:2
y.handle @ jquery.min.js:2
Also, I need to read this file object in Django's views.py.
javascript jquery ajax
marked as duplicate by mplungjan
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 5:59
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Minimum effort - you are not sending the correct data type
– mplungjan
Jan 3 at 6:01
@mplungjan I am sending an excel file object, what should be the correct data type?
– bSr
Jan 3 at 6:07
You should use the correct data type - look at the newest posts from here: google.com/…
– mplungjan
Jan 3 at 6:10
add a comment |
This question already has an answer here:
JQuery: 'Uncaught TypeError: Illegal invocation' at ajax request - several elements
8 answers
JQuery: 'Uncaught TypeError: Illegal invocation' at ajax request
1 answer
submit form with ajax but get “Illegal Invocation”
1 answer
How can I upload files asynchronously?
31 answers
I have an input tag in HTML
<input id="fileId" type="file" name="fileId" style="display:none;">
I need to receive this file object in javascript to pass it in back-end through ajax.
I am using below line to get file object.
var fileObject = $('#fileId').prop('files')[0]
I am able to receive the file object with this line of code.
and my ajax code is:
$.ajax({
type: 'POST',
url: '/urlname/',
data: {"file_object": fileObject},
success: function(data) {
console.log(data)
}
});
I am not able to execute the ajax code since it producing Illegal invocation error while parsing the object through the ajax.
below is the error trace:
jquery.min.js:2 Uncaught TypeError: Illegal invocation
at i (jquery.min.js:2)
at jt (jquery.min.js:2)
at Function.w.param (jquery.min.js:2)
at Function.ajax (jquery.min.js:2)
at HTMLButtonElement.<anonymous> (index.js:36)
at HTMLButtonElement.dispatch (jquery.min.js:2)
at HTMLButtonElement.y.handle (jquery.min.js:2)
i @ jquery.min.js:2
jt @ jquery.min.js:2
w.param @ jquery.min.js:2
ajax @ jquery.min.js:2
(anonymous) @ index.js:36
dispatch @ jquery.min.js:2
y.handle @ jquery.min.js:2
Also, I need to read this file object in Django's views.py.
javascript jquery ajax
This question already has an answer here:
JQuery: 'Uncaught TypeError: Illegal invocation' at ajax request - several elements
8 answers
JQuery: 'Uncaught TypeError: Illegal invocation' at ajax request
1 answer
submit form with ajax but get “Illegal Invocation”
1 answer
How can I upload files asynchronously?
31 answers
I have an input tag in HTML
<input id="fileId" type="file" name="fileId" style="display:none;">
I need to receive this file object in javascript to pass it in back-end through ajax.
I am using below line to get file object.
var fileObject = $('#fileId').prop('files')[0]
I am able to receive the file object with this line of code.
and my ajax code is:
$.ajax({
type: 'POST',
url: '/urlname/',
data: {"file_object": fileObject},
success: function(data) {
console.log(data)
}
});
I am not able to execute the ajax code since it producing Illegal invocation error while parsing the object through the ajax.
below is the error trace:
jquery.min.js:2 Uncaught TypeError: Illegal invocation
at i (jquery.min.js:2)
at jt (jquery.min.js:2)
at Function.w.param (jquery.min.js:2)
at Function.ajax (jquery.min.js:2)
at HTMLButtonElement.<anonymous> (index.js:36)
at HTMLButtonElement.dispatch (jquery.min.js:2)
at HTMLButtonElement.y.handle (jquery.min.js:2)
i @ jquery.min.js:2
jt @ jquery.min.js:2
w.param @ jquery.min.js:2
ajax @ jquery.min.js:2
(anonymous) @ index.js:36
dispatch @ jquery.min.js:2
y.handle @ jquery.min.js:2
Also, I need to read this file object in Django's views.py.
This question already has an answer here:
JQuery: 'Uncaught TypeError: Illegal invocation' at ajax request - several elements
8 answers
JQuery: 'Uncaught TypeError: Illegal invocation' at ajax request
1 answer
submit form with ajax but get “Illegal Invocation”
1 answer
How can I upload files asynchronously?
31 answers
javascript jquery ajax
javascript jquery ajax
edited Jan 3 at 5:58
mplungjan
89.7k22127184
89.7k22127184
asked Jan 3 at 5:55
bSrbSr
339415
339415
marked as duplicate by mplungjan
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 5:59
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by mplungjan
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 5:59
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Minimum effort - you are not sending the correct data type
– mplungjan
Jan 3 at 6:01
@mplungjan I am sending an excel file object, what should be the correct data type?
– bSr
Jan 3 at 6:07
You should use the correct data type - look at the newest posts from here: google.com/…
– mplungjan
Jan 3 at 6:10
add a comment |
Minimum effort - you are not sending the correct data type
– mplungjan
Jan 3 at 6:01
@mplungjan I am sending an excel file object, what should be the correct data type?
– bSr
Jan 3 at 6:07
You should use the correct data type - look at the newest posts from here: google.com/…
– mplungjan
Jan 3 at 6:10
Minimum effort - you are not sending the correct data type
– mplungjan
Jan 3 at 6:01
Minimum effort - you are not sending the correct data type
– mplungjan
Jan 3 at 6:01
@mplungjan I am sending an excel file object, what should be the correct data type?
– bSr
Jan 3 at 6:07
@mplungjan I am sending an excel file object, what should be the correct data type?
– bSr
Jan 3 at 6:07
You should use the correct data type - look at the newest posts from here: google.com/…
– mplungjan
Jan 3 at 6:10
You should use the correct data type - look at the newest posts from here: google.com/…
– mplungjan
Jan 3 at 6:10
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Minimum effort - you are not sending the correct data type
– mplungjan
Jan 3 at 6:01
@mplungjan I am sending an excel file object, what should be the correct data type?
– bSr
Jan 3 at 6:07
You should use the correct data type - look at the newest posts from here: google.com/…
– mplungjan
Jan 3 at 6:10