无法读取不确定&QUOT的财产“价值”;在道场/请求/ iframe的职位 [英] Cannot read property 'value' of undefined" on dojo/request/iframe post
问题描述
我有一个图片上传功能,上传的是,像这样的图像格式:
IFRAME(URL,{
形式:dom.byId(MyForm的),
handleAs:JSON
超时:5000,
方法:POST
})。然后(函数(){
的console.log(成功);
},函数(ERR){
的console.log(ERR);
});
在服务器端,我得到的形象,但在客户端上我得到的类型错误:在我[如用handleResponse(的 http://ajax.googleapis.com/ajax/libs/dojo/1.9.2/dojo/请求/ iframe.js:9:114 )↵在r(的 http://ajax.googleapis.com/ajax/libs/dojo/1.9.2/dojo/dojo.js:206:81 )我没有返回值!我不明白是什么导致了错误!
请帮助!
在的道场参考指南
重要:如果您的有效载荷是其他东西比HTML或XML(例如文本, JSON )服务器响应需要附上内容
在< TextArea>
标记。这是因为,这是唯一的跨浏览器
该供应商的方式来知道什么时候该内容已成功
加载。因此,服务器的响应应该是这个样子:
块引用>< HTML和GT;
<身体GT;
< TextArea>
有效载荷
< / textarea的>
< /身体GT;
< / HTML>所有你应该需要做什么来解决这个问题,是包装在
&LT你的JSON响应; textarea的>
标记。这样做的原因是iframe.js
,开始行300:如果(handleAs ==='XML'){
...
}其他{
//'JSON'和'的javascript'和'文字'
response.text = doc.getElementsByTagName('文本区域')[0] .value的; //文本
}因此,这里是你在哪里得到你的错误,上面写着无法读取的财产价值
未定义
。道场找不到< textarea的>
在你的反应元件,所以doc.getElementsByTagName('文本区域')
返回一个空数组。空数组的第0个元素,[]
是未定义
,并取消引用它会抛出这个错误。I have an image upload function that uploads form with image like this:
iframe(url, { form: dom.byId("myform"), handleAs: "json", timeout: 5000, method: "POST" }).then(function () { console.log("Success"); }, function (Err) { console.log(Err); });
On server side I get the image, but on client side I get TypeError: Cannot read property 'value' of undefined↵ at I [as handleResponse] (http://ajax.googleapis.com/ajax/libs/dojo/1.9.2/dojo/request/iframe.js:9:114)↵ at r (http://ajax.googleapis.com/ajax/libs/dojo/1.9.2/dojo/dojo.js:206:81)". I have no returned value! I do not get what causing the error! Please help!
解决方案From the Dojo Reference Guide:
Important: If your payload is something other than html or xml (e.g. text, JSON) the server response needs to enclose the content in a
<textarea>
tag. This is because this is the only cross-browser way for this provider to know when the content has been successfully loaded. Therefore the server response should look something like this:
<html> <body> <textarea> payload </textarea> </body> </html>
All you should need to do to fix this issue is to wrap your JSON response in a
<textarea>
tag. The reason for this is iniframe.js
, starting at line 300:if(handleAs === 'xml'){ ... }else{ // 'json' and 'javascript' and 'text' response.text = doc.getElementsByTagName('textarea')[0].value; // text }
So here is where you get your error that reads, "Cannot read property 'value' of
undefined
." Dojo can't find a<textarea>
element in your response, sodoc.getElementsByTagName('textarea')
returns an empty array. The 0th element of an empty array,[]
, isundefined
, and dereferencing it will throw this error.这篇关于无法读取不确定&QUOT的财产“价值”;在道场/请求/ iframe的职位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!