代码如下
: $(function() {
            $("#userid").blur(function() {
                if ($(this).val() != "") {
                    $.ajax({
                        type: "POST",
                        url: "UserRegister.aspx/ChangeID",
                        data: "{'id':'" + $(this).val() + "'}",
                        contentType: "application/json;charset=utf-8",
                        dataType: "text",
                        success: function(msg, dd, ss) {
                            alert(msg);
                        },
                        error: function(err) {
                            alert('获取信息失败');
                        }
                    })
                }            })
        })后台代码是:[System.Web.Services.WebMethod]
    public static  bool    ChangeID(string id)
    {
        LoginBll bll = new LoginBll();
        bool flag = bll.TrOrFa(id);        return flag;
    }
返回值alert(msg) 怎么是{"d":true}和{"d":false}; 我该怎样提出true和false呢?

解决方案 »

  1.   


     $(eval("(" + msg + ")").d)
      

  2.   

    msg = eval("(" + msg + ")");
    alert(msg.d);
      

  3.   

    学习一下json数据就明白了  2楼正解 我就不写了
      

  4.   

    jQuery(function($) {
        var username = $("#username");
        var pwd = $("#pwd");
        var code = $("#code");
        $("#oalogin").click(function() {
        $.post("Ajax/Help/Ajax_Help.ashx?method=login&date=" + new Date().getTime(), { Action: "post", username: username.val(), pwd: pwd.val(), code: code.val()},
            function(data, textStatus) {
                if (data.result == 'Eok') {
                    top.location.href = "index.aspx?a0e4=ee11cbb19052e40b07aac0ca060c23ee";
                }
                else if(data.result == 'Aok') { 
                    top.location.href = "index.aspx?a0e4=21232f297a57a5a743894a0e4a801fc3";
                }
                else {
                            if(data.result=="Code")
                            {
                               showMsgErr("RegVerifyCode_info","");
                               pass=false;
                               return false;
                               checkform();
                            }
                            else if(data.result=="UP")
                            {
                              showMsgErr("loginid_info","");
                              showMsgErr("password_info","");
                              pass=false;
                              return false;
                              checkform();
                            }
                            else
                            {
                              checkform();
                            }
                }         }, "json");
        });
    });
      

  5.   

    var StateID = $(this).parents('tr').attr('id'); 
    $.ajax({ 
        url: 'Remote/State.cfc' 
        ,data: { 
            method:'Delete' 
            ,'StateID':StateID 
        } 
        ,context: StateID 
        ,success: function(result){  
            alert(this);     // the value of StateID 
            alert(StateID);  // same as above 
             }; 
        } 
    }); 
      

  6.   


     <script language="javascript" type="text/javascript">
            function GetClientInfo() {
                var RepairNo = $.trim($("#txtRepairsNo").val());            if (RepairNo.length == 0) {
                    //                alert('请输入报修单号!');
                    return false;
                }
                $.get("../ashx/Handler.ashx?strstate=Entrance&strRepairNo=" + RepairNo, function(data) {
                    if (data != "") {
                        var arrInfo = data.split(',');
                        $("#txtCarNo").val(arrInfo[0]);
                        $("#txtCarModel").val(arrInfo[1]);
                        $("#txtClientName").val(arrInfo[2]);
                        $("#txtLinkMan").val(arrInfo[3]);
                        $("#txtLinkManTel").val(arrInfo[4]);
                        $("#txtClientNo").val(arrInfo[5]);
                        $("#txtServerName").val(arrInfo[6]);
                       
                    }
                });
            }
        </script> 
      

  7.   


    <%@ WebHandler Language="C#" Class="Handler" %>using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using GarageWebService;
    public class Handler : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";        if (context.Request.HttpMethod == "GET")
            {
                //string strNo = context.Request.QueryString["strRepairNo"].ToString();
               // string strstate=context.Request.QueryString["strstate"].ToString();
               string strstate = "InitTask";
               string strNo = "1000141252";
                if (strstate == "Entrance")
                {
                    //string strNo = "1000141252";
                    if (!string.IsNullOrEmpty(strNo))
                    {                    GarageWebService.TYMics2CarInfo GetFristTaskinfo = new GarageWebService.TYMics2CarInfo();
                        DataTable dt = GetFristTaskinfo.GetFristTaskInfo(strNo);
                        if (dt == null)
                        {
                            context.Response.Write("<script>alert('取到的值为空!');</script>");
                        }
                        else
                        {
                            DataRow row = dt.Rows[0];
                            context.Response.Write(row["vehicleNumber"].ToString() + ","
                                + row["vehicleTypeNumber"].ToString() + ","
                                + row["people"].ToString() + ","
                                + row["person"].ToString() + ","
                                + row["phone"].ToString() + ","
                                + row["ClientID"].ToString() + ","
                                + row["operationName"].ToString());
                            // + "," + row["ClientID"].ToString()
                            // + row["bulletinRepair"].ToString() + ",
                            //
                        }
                    }
                }
                if (strstate == "InitTask")
                {
                    if (!string.IsNullOrEmpty(strNo))
                    {                    GarageWebService.TYMics2CarInfo GetFristTaskinfo = new GarageWebService.TYMics2CarInfo();
                        DataTable dt = GetFristTaskinfo.GetFristTaskInfo(strNo);
                        if (dt == null)
                        {
                            context.Response.Write("<script>alert('取到的值为空!');</script>");
                        }
                        else
                        {
                            DataRow row = dt.Rows[0];
                            context.Response.Write(row["vehicleNumber"].ToString() + ","
                                + row["vehicleTypeNumber"].ToString() + ","
                                + row["people"].ToString() + ","
                                + row["person"].ToString() + ","
                                + row["phone"].ToString() + ","
                                + row["operationName"].ToString() + ","
                                + row["bulletinRepair"].ToString() + ","
                                + row["bulletinRepair"].ToString());
                            // + "," + row["ClientID"].ToString()
                            // + row["bulletinRepair"].ToString() + ",
                            //
                        }
                    }
                    
                }
            }
            
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }}