weixin_33728708 2015-12-17 18:07 采纳率: 0%
浏览 31

未定义-Ajax方法错误

I looked most of questions like this and i tried a lot of methods to solve the problem but i couldn't.

var kullaniciAdi = '<%= Session["kullanici"] %>';
    alert(kullaniciAdi);
    $.ajax({
        url: "http://localhost:63000/GetInfoService.asmx/GetInfos",
        type: "POST",
        dataType:'json',
        data: JSON.stringify({ kullaniciAdi: kullaniciAdi }),
        contentType: "application/json; charset=windows-1254",
        success: function (infos) {
            var items = infos.d;
            $jQuery.each(items, function (index, val) {
                $("div#adSoyad").html('<h1>' + val[index].ad + " " + val[index].soyad + '</h1>');
                $("div#fotograf").html('<img src="' + val[index].fotograf + '" class="img-responsive">');
            });
        },
        error: function (e) {
            alert(e.leader);
        }
    });

it's not working no matter what i did. i tried to turn index to 0 or remove them nothing worked.

here is my service that i have been calling:

 public class GetInfoService : System.Web.Services.WebService
{
    [WebMethod]
    public List<kullaniciBilgileri> GetInfos(string kullaniciAd)
    {
        List<kullaniciBilgileri> infos = new List<kullaniciBilgileri>();
        try
        {
            SqlConnection conn = new SqlConnection("Data Source=.\\SQLExpress; Initial Catalog=twitter;Integrated Security=SSPI");
            if (conn.State == ConnectionState.Closed)
                conn.Open();

            SqlCommand cmd = new SqlCommand("SELECT ad,soyad,fotograf FROM tblKullanici WHERE kullaniciAdi = @kullaniciAd");
            cmd.CommandType = CommandType.Text;
            cmd.Connection = conn;
            cmd.Parameters.AddWithValue("@kullaniciAd", kullaniciAd);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                var kullanici = new kullaniciBilgileri
                {
                    ad = dr["ad"].ToString(),
                    soyad = dr["soyad"].ToString(),
                    fotograf = dr["fotograf"].ToString()
                };
                infos.Add(kullanici);
            }
            return infos;
        }
        catch (SoapException se)
        {
            throw se;
        }
    }
    public class kullaniciBilgileri
    {
        public string ad { get; set; }
        public string soyad { get; set; }
        public string fotograf { get; set; }
    }
}

and for more information this method my login and home page. maybe there are mistakes that i've made.

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    [WebMethod]
    public static string GetSessionValue(string kullaniciAd)
    {
        HttpContext.Current.Session["kullanici"] = kullaniciAd;
        return kullaniciAd;
    }
}

 public partial class Home : System.Web.UI.Page
{       
    protected void Page_Load(object sender, EventArgs e)
    {
        if (HttpContext.Current.Session["kullanici"] == null)
        {
            Response.Redirect("Login.aspx");
        }
    }

}

sorry for my English :)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog