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 :)