我有一个简单的html页面 - :
$.getJSON("http://www.bebas.co.in/myservice.asmx/functionName?callback=?",
function(response) {
//manipulate response
});
///
在myservice.cs文件中我有这个..
[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 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 myservice : System.Web.Services.WebService
{
public myservice()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string functionName()
{
//database access..
Dictionary<string, object> result = new Dictionary<string, object>();
result = JsonMethods.ToJson(dsResult.Tables[0]);
//other operations...
return new JavaScriptSerializer().Serialize(result);
}
}.................
我想要跨域访问...但我无法这样做..firebug给了我 对于意外以...结尾的URL无法识别请求格式
我该怎么办?。
答案 0 :(得分:0)
您不需要Web服务来返回JSON。只需将代码放在一个普通的webform中(没有标记,只是一个空格.aspx),然后在代码隐藏(.aspx.cs)中的Page_Load()中调用它。
或者您可以使用HttpHandler。