日期:2014-05-16  浏览次数:20730 次

jquery ajax回传没有值
 $.ajax({ 
            type: "post",
            url: "LogoHandler.ashx",
            data: { User: username.value, PassWord: userpass.value },
            success: function (msg) {
                alert(msg)
            } 
        });


后台LogoHandler.ashx
Imports System.Web
Imports System.Web.Services

Public Class LogoHandler
    Implements System.Web.IHttpHandler
     

    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        Dim User As String = Convert.ToString(context.Request.Params("User"))

        Dim IsOk As String = "1"
        context.Response.ContentType = "text/plain"
        context.Response.Write(IsOk) 
    End Sub

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


后台能取到值,在返回前台时,取不到值。
------解决方案--------------------
alert(msg)没有执行到这句还是输出为空?

没执行到说明动态页出问题了。

    $.ajax({
        type: "post",
        url: "LogoHandler.ashx",
        data: { User: username.value, PassWord: userpass.value },
        success: function (msg) {
            alert(msg)
        },
        error: function (xhr) { alert(xhr.responseText)}

    });
------解决方案--------------------
你怎么知道执行到success,肯定就么有执行success了,所以才没有alert(msg)..

加了error回调没有,是否执行了error
------解决方案--------------------
 error:  看看有没有错误信息。
------解决方案--------------------
$.ajax({
         type: "post",
         url: "LogoHandler.ashx",
         data: { User: username.value, PassWord: userpass.value },
         success: function (msg) {
             alert(0)