[英]Object of type 'Object' cannot be converted to type 'Array'
I have read about this error many articles, I have tried many solutions but nothing is working! 我已经阅读了很多有关此错误的文章,我尝试了许多解决方案,但是没有任何效果! I am stuck with this error since 3 days I hope someone can help me, thanks!
自3天以来,我一直遇到这个错误,希望有人可以帮助我,谢谢! What I'm doing is calling my webservice from my mypage.aspx through two ways:
我正在做的是通过两种方式从mypage.aspx调用Web服务:
A-) 一种-)
MyWebservice.MyWebMethod("test",LunchMyFunction);
function LunchMyFunction(response) {
alert(response); // [object Object]
var gridView = $find('<%= MyGridView.ClientID %>');
gridView.set_dataSource(response);
gridView.dataBind();
}
Here the gridview is filled properly and everything is ok. 在这里,gridview正确填充,一切正常。
B-) B-)
$.ajax({
type: "POST",
url: 'MyWebservice.asmx/MyWebMethod',
data:{ testVal : "test" },
success: function (response) {
alert(response); // [object XMLDocument]
var gridView = $find('<%= MyGridView.ClientID %>');
try {
gridView.set_dataSource(response);
} catch (err) {
alert(err);
}
gridView.dataBind();
},
error: function (err) { alert(err.statusText); }
});
Here my web method is completing it's work but when it comes to setdatasource : an error is thrown: Sys.ArgumentTypeException: Sys.ArgumentTypeException: Object of type 'Object' cannot be converted to type 'Array'.
在这里,我的Web方法正在完成其工作,但是当涉及setdatasource时:引发错误: Sys.ArgumentTypeException:Sys.ArgumentTypeException:类型为“ Object”的对象无法转换为类型为“ Array”的对象。
Parameter name: value
参数名称:值
I thought that this error is thrown because response type is different in both cases, so I have tried to set types as json to return [object Object]. 我认为抛出此错误是因为两种情况下的响应类型都不同,因此我尝试将类型设置为json以返回[object Object]。 After returning Object the method still throws the same error.
返回Object之后,该方法仍会引发相同的错误。 I have tried ScriptMode="Release" in my ToolkitScriptManager which is in my Master page not in mypage.aspx, but nothing have changed.
我已经在我的母版页而不是mypage.aspx中的ToolkitScriptManager中尝试了ScriptMode =“ Release”,但是没有任何更改。
<cc1:ToolkitScriptManager ScriptMode="Release" ID="ToolkitScriptManager1" AsyncPostBackTimeout="600" EnablePartialRendering="true" EnablePageMethods="true" runat="server">
<Services>
<asp:ServiceReference path="MyWebservice.asmx" />
</Services>
<Scripts>
<asp:ScriptReference path="~/JavaScript/WebKitFix.js" />
</Scripts>
</cc1:ToolkitScriptManager>
The assembly of cc1 is AjaxControlToolkit, and mypage.aspx is included in Master Page. cc1的程序集是AjaxControlToolkit,而mypage.aspx包含在“母版页”中。 Any idea about what could be the problem?
关于可能是什么问题的任何想法? How can I resolve it?
我该如何解决?
Finally, after searching I discovered that in the second method response is: 最后,在搜索之后,我发现第二种方法的响应是:
{"d":[{"__type":"UploadedFile","Success":"Success","UploadedURL":"Uploaded URL"}]}
while what I need was response.d to return this:
而我需要的是response.d返回此:
[{ "__type": "UploadedFile", "Success": "Success", "UploadedURL": "Uploaded URL"}]
That was my error, thank you 那是我的错,谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.