• 01-12-2009, 20:55:53
    #1
    fonksiyon içinde XmlHttpRequestObject i alert ile bastırdırtığımda Object XmlhttpRequest diyor yani bir problem yok ama onreadystatechange içinde aynı alert ile bastırdığımda undefined olarak gösteriyor

    neden kaynaklanabilir ? kodlar kısaca :

    function chatSession(){
    
        this.getXmlHttpRequestObject = function() {
               
                if (window.XMLHttpRequest) {
                    return new XMLHttpRequest();
                    } else if(window.ActiveXObject) {
                    return new ActiveXObject("Microsoft.XMLHTTP");
                    } else {
                    document.getElementById('p_status').innerHTML = 'eror, errorr, errrrrorrrrrr!!.';
                    }
            }
    
        this.sendReq = this.getXmlHttpRequestObject();
        this.receiveReq = this.getXmlHttpRequestObject();
    
        //sayfa yüklenince çalışan fonksiyon
                this.startChat = function() {
                    //Set the focus to the Message Box.
                    document.getElementById('txt_message').focus();
                    //Start Recieving Messages.
                    this.getChatText();
                }    
    
    //problem yaratan fonksiyon
        this.getChatText = function() {
               
                    if (this.receiveReq.readyState == 4 || this.receiveReq.readyState == 0) {
                       
                        this.receiveReq.open("GET", 'getChat.php?chat=1&last=' + this.lastMessage, true);
                        alert('getcharText ici receiveReq: ' + this.receiveReq + 'this.receiveReq.readyState: ' + this.receiveReq.readyState);
    // bu alert düzgün sonuç veriyor (xmlhttpobject)
                        
                        this.receiveReq.onreadystatechange = function(){
                            // bu alert undefined veriyor :(                
                            alert('readystate ici receiveReq: ' + this.receiveReq);
                            alert('getChatText readystate' + this.sendReq.readyState);
                            // console.log(httpRequest.readyState);
                            if (this.receiveReq.readyState == 4) {
                            alert('getChatText if ici readystate' + this.receiveReq.readyState);    
                            this.handleSendChat(this.receiveReq);
                            }
                        };
                        
                        this.receiveReq.send(null);
                        // alert('np getChatText');
                    }    
                    // else {alert('ajax eror');}        
                }
    
    }
  • 17-12-2009, 17:30:10
    #2
    jQuery ve JSON kullanmanı tavsiye ederim.
    PHP de json nasıl yapılır bilmiyorum ama asp.net te çocuk oyuncağı.
    PHP için açık kaynak json çeviriciler vardır. Çok işine yarar jquery ile hem kodlaman rahatlar