问候,
我到处寻找,我看到的每个答案都告诉我将以下内容放在我的web.config中:
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
Run Code Online (Sandbox Code Playgroud)
所以我已经做到了,我仍然得到错误.
这是我网页上的脚本:
<script>
$(function () {
$('#btn').click(
function () {
CallHome();
}
);
});
function CallHome() {
$.ajax({
type: "POST",
url: "HelloWorld.asmx/HelloWorld",
dataType: "xml",
data: "{}",
contentType: "xml",
success: function(data) {
alert(data);
}
});
}
</script>
Run Code Online (Sandbox Code Playgroud)
WebService.vb是:
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Web.Script.Services
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class HelloWorld
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello World" …Run Code Online (Sandbox Code Playgroud) 问候,
无论我做什么,我都无法从ashx处理程序页面获取我的jquery ajax代码以获得除null之外的响应.
这是我的hmt页面:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>:: ashx tester ::</title>
<link rel="stylesheet" href="js/jqueryui/1.8.6/themes/sunny/jquery-ui.css"
type="text/css" media="all" />
<script type="text/javascript" src="js/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript" src="js/jqueryui/1.8.6/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/json2/0.0.0/json2.js"></script>
<script type="text/javascript">
$(function () {
$('#btnSubmit').click(
function () {
DoIt();
}
);
});
function DoIt() {
$('#btnSubmit').hide();
$.ajax({
type: "POST",
url: "http://localhost:49424/Handler1.ashx",
data: {
firstName: 'Bob',
lastName: 'Mahoney'
},
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (response) {
alert('success: ' + response);
$('#btnSubmit').show();
},
error: function (response) {
alert('error: …Run Code Online (Sandbox Code Playgroud)