从WebMethod返回值到javascript获取未定义错误 [英] Return value from WebMethod to javascript getting undefined error
问题描述
将值从WebMethod返回到javascript会得到未定义的错误?
在这里,IAM在js文件中使用webmethod调用,如
Return value from WebMethod to javascript getting undefined error?
here iam using webmethod call in js file like
GetFields(fieldName, _ID, myEditor.onGetFieldsCompleted, myEditor.onGetFieldsFailed);
webservice.cs文件
webservice.cs file
[WebMethod]
public string[] GetFields(string mergeFieldName, Int32 PartnershipID)
{
string[] stringArray = (string[])fields.ToArray(typeof(string));
return stringArray ;
}
在这里,从Web服务中,我们正在将字符串数组返回给javascript……这时,iam会以未定义错误的形式返回到javascript中……请参见下面的js文件代码.......
onGetFieldsCompleted = function(result)----------在此结果IAM变得未定义.....我必须获取字符串数组,该字符串数组是我从WebMethod返回的结果,但IAM在结果中变得未定义... ............
here from webservice we are returning string array to javascript ......at tht time iam getting reult in javascript as undefined error ......pls see below js file code ........
onGetFieldsCompleted = function (result)----------here in result iam getting undefined.....actualy i have to get string array whcih i returned from webmethod in result but iam getting undefined in result...............
{
if (result != null) {
if(result.length > 0) {
}
else {
}
}
请帮助我....
推荐答案
您可以尝试使用
You can try to use System.Collection.Generic.List<t> for the return value of your WebMethod.
首先您不能像这样简单地写它的名称和passwing参数列表来调用您的webservice方法.
GetFields(fieldName,_ID,myEditor.onGetFieldsCompleted,myEditor.onGetFieldsFailed);
您可以使用jquery的最常用方法之一来调用您的服务
first of all you can not call your webservice method by simply write it''s name and passwing parameter list like this....
GetFields(fieldName, _ID, myEditor.onGetFieldsCompleted, myEditor.onGetFieldsFailed);
you can call your serivce by using one of the most common method of jquery
.ajax()这样.
.ajax() like this.
function callWebService() {
var _data = "{mergeFieldName:'YOUR VALUE',PartnershipID:'YOUR VALUE'}";
var _url = "YOUR SERVICE URL"
这篇关于从WebMethod返回值到javascript获取未定义错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!