问题原因是什么???我尝试了很多不同的方法,但无法访问 Web 服务的“hello world”方法。我找不到问题的原因。我的结构如下所示。
网络服务 :
[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 Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
JavaScript:
<script src="js/jquery.js" type="text/javascript" ></script>
<script src="js/jquery-1.9.0.min.js" type="json/javascript" ></script>
<script src="js/jquery.mobile-1.2.0.min.js" type="text/javascript" ></script>
<script type="text/javascript">
app.initialize();
$.ajax(
{
type: "POST",
url: "http://localhost:49182/Service1.asmx?op=HelloWorld",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
sucess: function() { console.log('response.responseText'); },
error: function() { console.log('error'); }
});
</script>
</head>
控制台总是给出错误信息。