gpt4 book ai didi

jquery ajax 从 ashx 处理程序获取返回值时出现问题

转载 作者:行者123 更新时间:2023-12-03 22:52:11 24 4
gpt4 key购买 nike

问候,

无论我做什么,我都无法让我的 jquery ajax 代码从 ashx 处理程序页面获取除 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: ' + response);
$('#btnSubmit').show();
}
});
}
</script>
</head>
<body>
<input id="btnSubmit" type="button" value="Submit" />
</body>
</html>

这是我的 ashx 页面:

Imports System.Web
Imports System.Web.Services
Imports System.Collections.Generic
Imports System.Linq
Imports System.Data
Imports System.Configuration.ConfigurationManager
Imports System.Web.Services.Protocols
Imports System.Web.Script.Serialization

Public Class Handler1
Implements System.Web.IHttpHandler

Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim j As New System.Web.Script.Serialization.JavaScriptSerializer
Dim s As String

s = j.Serialize(Now)
context.Response.ContentType = "application/json"
context.Response.Write(s)

End Sub

ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property

End Class

有什么线索吗?

谢谢!

戴夫

最佳答案

尝试一下 url: "/Handler1.ashx",

而不是

 url: "http://localhost:49424/Handler1.ashx",

关于jquery ajax 从 ashx 处理程序获取返回值时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5561791/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com