js代码不能将数据发送到WebService1.asmx中对应的方法,只能进入insertCallbackSelsectSma提示错误的函数,以下是代码
js代码:
function GetClassByItemIdcy(id) {
var data = "{id:" + parseInt(id) + "}";
//alert(data);
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebService1.asmx/SelectAllClassByItemId",
data: data,
dataType: "json",
success: insertCallbackSelsectSma,
error: errorCallbackSelsectSma
});
}
function insertCallbackSelsectSma(result) {
$("#DropDownList1").find("option").remove();
var i = result.d;
//alert(i);
if (result["d"].length > 0) {
for (var i = 0; i < result["d"].length; i++) {
var classsma = eval(result["d"][i]);
alert(classsma.Class_Id);
$("#DropDownList1").append('<option value="' + classsma.ClassId + '">' + classsma.ClassName + '</option>');
}
}
}
function errorCallbackSelsectSma(XMLHttpRequest, textStatus, errorThrown) {
alert("错误1");
}页面中的dropdownlist <asp:DropDownList ID="DropDownList2" runat="server" onchange="GetClassByItemIdcy(this.value)">WebService1.asmx 中的代码
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<ClassEntity> SelectAllClassByItemId(int id)
{
classbllall = new ClassBll();
return classbllall.ClassSelectIdById(id);
}
js代码:
function GetClassByItemIdcy(id) {
var data = "{id:" + parseInt(id) + "}";
//alert(data);
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebService1.asmx/SelectAllClassByItemId",
data: data,
dataType: "json",
success: insertCallbackSelsectSma,
error: errorCallbackSelsectSma
});
}
function insertCallbackSelsectSma(result) {
$("#DropDownList1").find("option").remove();
var i = result.d;
//alert(i);
if (result["d"].length > 0) {
for (var i = 0; i < result["d"].length; i++) {
var classsma = eval(result["d"][i]);
alert(classsma.Class_Id);
$("#DropDownList1").append('<option value="' + classsma.ClassId + '">' + classsma.ClassName + '</option>');
}
}
}
function errorCallbackSelsectSma(XMLHttpRequest, textStatus, errorThrown) {
alert("错误1");
}页面中的dropdownlist <asp:DropDownList ID="DropDownList2" runat="server" onchange="GetClassByItemIdcy(this.value)">WebService1.asmx 中的代码
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<ClassEntity> SelectAllClassByItemId(int id)
{
classbllall = new ClassBll();
return classbllall.ClassSelectIdById(id);
}
解决方案 »
- worldwind c#版有像java版那样的API吗
- C# 3.0中对象构造器可以访问私有成员??
- 跟我学MVVM模式开发(2)
- 存储过程中,如何将值传递到ROW_NUMBER() OVER(ORDER BY @input) 的参数?
- 如何实现textbox与文本绑定!!
- 利用ajax无刷新更新GridView后不能编辑
- [再发]WinForm超难问题,两天了也没有解决,各位高手帮帮我.120分在线等
- 如何读outlook *.msg文件,最好转化成html,xml
- C#开发SIP客户端,发送消息后,返回400错误,CallID空了
- 线程中启动定时器的问题。
- 急!!!在线等!!!IIS配置后,网站的按钮不见了。IIS配置后,用IIS启动网站后,发现原网站上的按钮不见了。
- C# 如何做条码识别与指纹识别软件啊?
http://msdn.microsoft.com/zh-cn/magazine/cc163499.aspx