C# can';t从jquery数据源调用webmethod
我试图用SQL Server中的数据填充jqxgrid。我遵循jqwedgets声明的所有指令从SQL Server获取数据,但由于某些原因,什么都没有发生。网格显示为空,没有数据 我正在使用以下代码: 脚本:C# can';t从jquery数据源调用webmethod,c#,jquery,C#,Jquery,我试图用SQL Server中的数据填充jqxgrid。我遵循jqwedgets声明的所有指令从SQL Server获取数据,但由于某些原因,什么都没有发生。网格显示为空,没有数据 我正在使用以下代码: 脚本: $(document).ready(function () { var url = "/test.aspx/Getquestions"; // prepare the data var source = { datatype: "xml", datafields:
$(document).ready(function () {
var url = "/test.aspx/Getquestions";
// prepare the data
var source = {
datatype: "xml",
datafields: [{ name: 'QuestionID' },
{ name: 'QuestionText' },
{ name: 'NumberofAnswers' }],
async: false,
record: 'question',
url: url
};
var dataAdapter = new $.jqx.dataAdapter(source, {
contentType: 'application/json; charset=utf-8' });
});
C#代码
我试图直接从浏览器调用webservice,但出现404错误。以下是web服务类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
//using System.Collections.Generic;
using System.IO;
using System.Web.Script.Services;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Script.Serialization;
namespace CIS
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
//[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)]
public string Getquestions()
{
return "hello";
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.Services;
使用System.Web.UI;
使用System.Web.UI.WebControl;
//使用System.Collections.Generic;
使用System.IO;
使用System.Web.Script.Services;
使用系统数据;
使用System.Data.SqlClient;
使用系统配置;
使用System.Web.Script.Serialization;
名称空间CI
{
///
///WebService 1的摘要说明
///
[WebService(命名空间=”http://tempuri.org/")]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
//要允许使用ASP.NET AJAX从脚本调用此Web服务,请取消注释以下行。
[System.Web.Script.Services.ScriptService]
公共类WebService 1:System.Web.Services.WebService
{
[网络方法]
//[ScriptMethod(UseHttpGet=true,ResponseFormat=ResponseFormat.Xml)]
公共字符串Getquestions()
{
回复“你好”;
}
}
}
根本没有调用webmethod。
我测试了webmethod函数,它运行正常。它创建了xml。但是由于某些原因,url属性没有调用webmethod。有什么帮助吗 我认为您需要从方法定义中删除
static
公共字符串Getquestions()
如果这不起作用,我建议使用Fiddler或Wireshark之类的网络流量分析器来确认是否发送了web请求。我从方法中删除了static,但仍然不起作用。我还尝试了Fiddler,它告诉我调用该方法时出现了404错误。阿美称之为错误way@mohamedbaradie-也许吧。你发布的C代码是什么类型的文件?还可以显示包含此方法的类吗?另外,您能告诉我在发出请求时使用了什么HTTP动词吗?动词应该在Fiddler流量中可见。我试图直接从浏览器调用webservice,但出现404错误。用整篇文章编辑问题class@mohamedbaradie-你确定你的文件是test.aspx而不是test.asmx吗?实际上是调用webservice1.asmx,我将url更改为这样。但实际上,当尝试从浏览器调用webservice时,它会给我404错误