the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework -
Hello,
This definitely makes sense. We'll investigate, but for the moment you can use the global
jQuery Ajax handlers
.
Apologies for the caused inconvenience.
Regards,
T. Tsonev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework -
download Kendo UI
now!
I'm using the example provided in the docs below to add an authorization header but I am noticing the event listener is getting called multiple times with a readyState of 1.
http://docs.telerik.com/kendo-ui/api/javascript/ui/upload#events-upload
The first time it gets called you can of course successfully add the header but the next time it gets called it throws back JavaScript runtime error: InvalidStateError.
I can overcome this by storing a flag that indicates the headers have already been added but why not just add some sugar to the upload widget for adding headers so we don't have to keep track of whether headers have already been added to the request?
We have met this strange issue before. It turned out that Internet Explorer fires
readystatechange
twice with
readyState
1 and the second execution of the handler causes the error. I assume that this could also be reproduced outside of the Kendo UI Upload widget environment with a standard XMLHttpRequest. Nevertheless as a workaround for the the current case you could name the executed handler and unbind it after the first execution.
function
onUpload(e) {
var
xhr = e.XMLHttpRequest;
if
(xhr) {
xhr.addEventListener(
"readystatechange"
,
function
onReady(e) {
if
(xhr.readyState == 1
/* OPENED */
) {
xhr.setRequestHeader(
"foo"
,
"bar"
);
xhr.removeEventListener(
"readystatechange"
, onReady);
Have a great day!
Regards,
Dimiter Madjarov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework -
download Kendo UI
now!
Hello there, a year has passed since your last response. Did you have any news for that?
Using global ajax handlers fixed my problem but it makes my code a bit messy and I was wondering if anything changed since last year.
Thank you.
Hello Thomas,
If you are referring to the last mentioned issue is not Kendo UI Upload related, but Internet Explorer related, as it fires the
readystatechange
twice with
readyState
1. As for the previous one, at the moment we do not provide access to the XHR in the remove event handler.
Regards,
Dimiter Madjarov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework -
download Kendo UI
now!
Hello Thomas,
At the moment the XHR is not available in the remove event handler. I will forward the request for review to the developers team.
Regards,
Dimiter Madjarov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework -
download Kendo UI
now!
Hello Thomas,
We have this logged for future implementation, but don't have an exact time span to state.
Regards,
Dimiter Madjarov
Telerik by Progress
Get started with Kendo UI in days.
Online training courses
help you quickly implement components into your apps.
Hello Thomas,
Here is the
GitHub issue
for the mentioned case. We have this in our short term development plans for the next Q.
Regards,
Dimiter Madjarov
Telerik by Progress
Build rich, delightful, *native* Angular 2 apps with
Kendo UI for Angular 2
.
Try it out today
! Kendo UI for Angular 2 (currently in beta) is a jQuery-free toolset, written in TypeScript, designed from the ground up to offer true, native Angular 2 components.
Hello Thomas,
In the next official release we will expose an
e.headers
parameter to the remove event, which will allow attaching custom request headers to the request.
Regards,
Dimiter Madjarov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components
built from ground-up which
deliver the business app essential building blocks - a grid component,
data visualization (charts) and form elements.
i´ve try this Example, but the Readystate is Alwayse "0".
how can we solve the Problem ?
01.
function
onUpload(e) {
02.
var
xhr = e.XMLHttpRequest;
03.
if
(xhr) {
04.
xhr.addEventListener(
"readystatechange"
,
function
(e) {
05.
if
(xhr.readyState == 1
/* OPENED */
) {
06.
xhr.setRequestHeader(
"X-Foo"
,
"Bar"
);
07.
}
08.
});
09.
}
10.
}
Hi Dennis,
Generally speaking, 0 for the readyState of the XMLHttpRequest means that the request is still not initialized. Prior to triggering the upload event, the XHR is created and if the upload is not prevented, open method is invoked and the readystatechange should be fired.
So, I would need more details on the matter - configuration of the upload or a sample project illustrating the issue - in order to diagnose the cause of the issue. The only reason that I could come up is if the upload gets prevented somewhere in your project logic, and thus, leading to not loading the xhr.
The example from this thread could be observed and run in our documentation:
https://docs.telerik.com/kendo-ui/api/javascript/ui/upload/events/upload
I am looking forward to your reply.
Regards,
Joana
Progress Telerik
Get
q
uickly onboarded and successful
with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers.
Learn More
.