【发布时间】:2013-12-16 10:36:08
【问题描述】:
我对 asp.net 和 web 服务很感兴趣。 我正在开发调用 asp.net web-service 的 HTML 5 应用程序。 我已经在 IIS7 上发布了我的 asp.net Web 服务,它工作正常,但是当我通过外部 HTML 5 JQuery 调用 Web 服务时,它给了我未定义的错误。
以下是我的网络服务代码:
using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
[WebService(Namespace = "http://tempuri.org/")]
[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 Service : System.Web.Services.WebService
{
public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Byeeee";
}
}
我的 Jquery 代码是:
// JavaScript Document
$(document).ready(function() {
$.ajax({
type: "POST",
url: "http://localhost/mywebserice/Service.asmx?op=HelloWorld",
Content-Type: 'application/x-www-form-urlencoded',
dataType: "xml",
data: '{}',
success: function(){
alert("Success");
},
error: function(){
alert("Error");
}
});
});
我的 HTML5 代码是:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="jquery-1.10.2.js"></script>
<script type="text/javascript" src="newJS.js"></script>
</head>
<body>
</body>
</html>
谁能帮我解决这个问题?
【问题讨论】:
-
在 jQuery 中将
url设为:http://localhost/mywebserice/Service.asmx/HelloWorld -
感谢您的回复。但是当我将 url 设置为 localhost/mywebserice/Service.asmx/HelloWorld 时,它什么也没显示
标签: c# asp.net html web-services jquery