使用knockout js从javascript调用webservice方法 [英] calling webservice methods from javascript with knockout js

查看:53
本文介绍了使用knockout js从javascript调用webservice方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,

i确实要求从javascript调用webservice方法。

i编写了如下代码。

在.asmx页面

[webmethod]

公开列表< substation> GetsubstationsData()

{

返回bcommon.GetSubstationdetails();

}

....

和aspx页面

< select data-bind =options:substationvalues,optionText:'substationname',optionvalue:'substationid',value:selectedsubstationid,optionscaption:'select变电站'/>


js文件中的


功能变电站(数据)

{

var self = this;

self.substationname = ko.observable(data.substationname);

self.substationid = ko.observable(data.substationid );

}

函数datamodel()

{

var self = this;

self.substationvalues = ko.observablearray([]);

self.selectedsubstationid = ko.observable();

fetchsubstationsdata = function(){

$ .ajax({

类型:'获取',

dataType:'json',

url: 'service1.asmx / GetsubstationsData',

成功:函数(数据){

//我的装订代码;

}

}

});

}

}

我也想在webservice中调用addmethod,因为我应该在上面的ajax调用中使用type作为'post'。???,上面的函数不能正常工作对我来说

显示请求的网址格式不支持...错误,我怎么能实现这个...请帮我解决这个问题。

解决方案

.ajax({

类型:'获取',

dataType:'json',

url:'service1 .asmx / GetsubstationsData',

成功:函数(数据){

//我的绑定代码;

}

}

});

}

}

我也想在webservice中调用addmethod ,为此我应该在上面的ajax调用中使用type作为'post'.... ???,上面的函数对我不起作用

显示请求的url格式不支持.. .error,我怎么能实现这个...请帮我解决这个问题。

Dear all,
i do have a requirement that to call a webservice method from javascript.
i have written the code as follows.
in .asmx page
[webmethod]
public list<substation> GetsubstationsData()
{
return bcommon.GetSubstationdetails();
}
....
and in aspx page
<select data-bind="options:substationvalues,optionText:'substationname',optionvalue:'substationid',value:selectedsubstationid,optionscaption:'select substation'"/>

in js file
function substationentity(data)
{
var self=this;
self.substationname=ko.observable(data.substationname);
self.substationid=ko.observable(data.substationid);
}
function datamodel()
{
var self=this;
self.substationvalues=ko.observablearray([]);
self.selectedsubstationid=ko.observable("");
fetchsubstationsdata=function(){
$.ajax({
type:'Get',
dataType:'json',
url:'service1.asmx/GetsubstationsData',
success:function(data){
//my binding code;
}
}
});
}
}
and also i want to call addmethod in webservice also, for that should i use type as 'post' in above ajax call....???, the above function is not working for me
it is showing requested url format is not supported...error, how can i achieve this...please help me to solve this.

解决方案

.ajax({
type:'Get',
dataType:'json',
url:'service1.asmx/GetsubstationsData',
success:function(data){
//my binding code;
}
}
});
}
}
and also i want to call addmethod in webservice also, for that should i use type as 'post' in above ajax call....???, the above function is not working for me
it is showing requested url format is not supported...error, how can i achieve this...please help me to solve this.


这篇关于使用knockout js从javascript调用webservice方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆