Durgut » ASP.NET

AJAX Temelleri-3 ile ilgili video

(7 mesaj(lar))
  1. elifayse

    offline
    Üye

    Merhaba,

    AJAX ile ilgili konu basligi olmadigi icin buraya yaziyorum. Umarim yanlis yapmiyorumdur.

    AJAX Temelleri-3 ile ilgili video'dakini yapmaya calistigimda bana soyle bir hata verdi:

    Microsoft JScript runtime error: 'xmlHttp.readyState' is null or not an object

    Video'daki kodun tipkisinin aynisini yazdim. Neden boyle bir hata aldigimi anlayamadim? Konuyla ilgili google'da biraz arastirdim. Bu ajax'in IE7 ile ilgili bir bug'ymis ama ben IE8 kullaniyorum.

    Bu problemi nasil asacagim ile ilgili yardimda bulunacak arkadaslara simdiden tesekkur ederim..

    7 months önce #
  2. fatihdurgut

    offline
    Yönetici

    kodunuda gonderir misin ?

    6 months önce #
  3. elifayse

    offline
    Üye

    Tabiki. Kod aynen soyle:

    Customer.htm

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
    <title></title>
    <script type="text/javascript">
    var xmlHttp;
    function showCustomer(str) {
    var xmlHttp;
    if (str == "-1") {
    document.getElementById("txtHint").innerHTML = "";
    return;
    }

    xmlHttp = GetXMLHttpObject();
    if (xmlHttp == null) {
    alert("browseriniz AJAX desteklemiyor");
    return;
    }

    var url = "getcustomer.aspx";
    url += "?q=" + str;
    xmlHttp.onreadystatechange = stateChanged;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
    }

    function stateChanged() {
    if (xmlHttp.readyState == 4) {
    document.getElementById("txtHint").innerHTML = xmlHttp.responseText;
    }
    else {
    document.getElementById("txtHint").innerHTML = "loading...";
    }
    }

    function GetXMLHttpObject() {
    var xmlHttp = null;
    try {
    xmlHttp = new XMLHttpRequest();
    }
    catch (e) {

    try{
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e){
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    }
    return xmlHttp;
    }

    </script>
    </head>
    <body>

    <select id="customer" onchange="showCustomer(this.value)">
    <option value="-1">Select One</option>
    <option value="ALFKI">Alfred</option>
    <option value="NORTS">North</option>
    <option value="WOLZA">Wolski</option>
    </select>
    <p>
    <div id="txtHint">
    <b>Customer info will be listed here</b>
    </div>
    </p>
    </body>
    </html>

    getcustomer.aspx

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Configuration;
    using System.Data.SqlClient;
    using System.Data;

    namespace AjaxOrnekleri
    {
    public partial class getcustomer : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    string connectionstring = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
    SqlConnection connection = new SqlConnection(connectionstring);
    string sql = "SELECT * FROM CUSTOMERS WHERE CUSTOMERID='"+Request.QueryString["q"]+"'";
    connection.Open();
    SqlCommand cmd= new SqlCommand(sql,connection);
    SqlDataReader dr= cmd.ExecuteReader(CommandBehavior.CloseConnection);
    Response.Write("<table>");
    while (dr.Read())
    {
    for (int i = 0; i < dr.FieldCount; i++)
    {
    Response.Write("<tr><td><b>"+dr.GetName(i).ToString()+"<b></td>");
    Response.Write("<td>"+dr.GetValue(i).ToString()+"</td></tr>");
    }
    }
    Response.Write("</table>");
    Response.End();
    }
    }
    }

    Web.config

    </sectionGroup>
    </sectionGroup>
    </configSections>
    <appSettings/>

    <connectionStrings>
    <add name="NorthwindConnectionString" connectionString="DataSource=.; Initial Catalog=Northwind; Integrated Security=True"/>
    </connectionStrings>

    <system.web>
    <!--
    Set compilation....

    6 months önce #
  4. onurtpl

    offline
    Üye

    "function showCustomer" satırının altındaki "var xmlHttp" satırını sil düzelmesi lazım.

    Bu şekilde bir aynı isimli bir xmlHttp objesi daha yaratılı ve bu durumlarda localdeki objeye öncelik verilir. yani xmlHttp = GetXMLHttpObject(); işlemi local objeye atanıyor.

    stateChanged de kullanılan global obje null olarak kullanılmaya çalışılıyor.

    6 months önce #
  5. elifayse

    offline
    Üye

    merhaba onurtpl,

    dediginiz gibi ilgili satiri sildim ama bu sefer de farkli bir exception firlatti. getcustomer.aspx dosyasindaki su satiri isaret ederek=
    SqlConnection connection = new SqlConnection(connectionstring);

    Bu hata mesajini verdi=
    Keyword not supported:'datasource'

    Customer.htm dosyasini calistirmadan once SQL Server'i acmistim. AYrica web.config dosyasindaki connectionString'i de su sekilde yazmistim=

    <connectionStrings>
    <add name="NorthwindConnectionString" connectionString="DataSource=.; Initial Catalog=Northwind; Integrated Security=True"/>
    </connectionStrings>

    ?:(

    6 months önce #
  6. onurtpl

    offline
    Üye

    "DataSource" u "Data Source" olarak dene.

    oda olmazsa Onu Server olarak değiştir.

    6 months önce #
  7. elifayse

    offline
    Üye

    Bu kadar kor oldugume inanmiyorum ya. Kafami nerelere vursam bilmiyorum ki:((

    Dedigin gibi "DataSource" u "Data Source" olarak denedim ve calisti.

    Cok tesekkur ederim onurtpl.
    Sagol.

    6 months önce #

Bu konu için RSS beslemesi

Cevapla

Mesaj göndermek için giriş yapmalısınız.