• 1 رای - 1 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
onreadystatechange اجرا نمیشود
#1
Exclamation 
من در صفحه ایی که طراحی کردم 3 المنت دارم که هر 3 یک کد ajax را اجرا میکنند. 2 تای آنها به خوبی و بدون مشکل اجرا میشود اما یکی از آنها حتی onreadystatechange را fire نمیکند تا وارد function آن شود، علت چیست؟

کدها به صورت زیر است:

کدهایی که اجرا میشود:
کد:
function nextChapter() {
                    if (document.getElementById('lastChapter').value != getQueryVariable('chapterid')) {
                        var book = getQueryVariable('bookid');
                        var chapter = parseInt(getQueryVariable('chapterid')) + 1;
                        var xmlhttp = new XMLHttpRequest();
                        xmlhttp.onreadystatechange = function () {
                        alert(xmlhttp.readyState + " " + xmlhttp.status);
                            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                                document.getElementById('bibleDesc').innerHTML = xmlhttp.responseText;
                                document.getElementById('showChapter').innerHTML = "باب " + chapter;
                                window.history.pushState(null, null, 'bible.php?bookid=' + book + '&chapterid=' + chapter);
                                ConvertNumberToPersion();
                            }
                        }
                        xmlhttp.open("GET", "verses.php?bookid=" + book + "&chapterid=" + chapter, true);
                        xmlhttp.send();
                        
                        if (document.getElementById('lastChapter').value == getQueryVariable('chapterid')) {
                            document.getElementById('rightArrow').src = "assets/rightarrowdisable.png";
                        } else {
                            document.getElementById('rightArrow').src = "assets/rightarrow.png";
                        }
                    }
                }
                
                function prevChapter() {
                    if (getQueryVariable('chapterid') != 1) {
                        var book = getQueryVariable('bookid');
                        var chapter = parseInt(getQueryVariable('chapterid')) - 1;
                        var xmlhttp = new XMLHttpRequest();
                        xmlhttp.onreadystatechange = function () {
                            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                                document.getElementById('bibleDesc').innerHTML = xmlhttp.responseText;
                                document.getElementById('showChapter').innerHTML = "باب " + chapter;
                                window.history.pushState(null, null, 'bible.php?bookid=' + book + '&chapterid=' + chapter);
                                ConvertNumberToPersion();
                            }
                        }
                        xmlhttp.open("GET", "verses.php?bookid=" + book + "&chapterid=" + chapter, true);
                        xmlhttp.send();
                        
                        if (document.getElementById('lastChapter').value == 1) {
                            document.getElementById('rightArrow').src = "assets/leftarrowdisable.png";
                        }
                    }
                }

و کدی که اجرا نمیشود:

کد:
function selectChange(obj) {
                    if (obj == document.getElementById('selectOld')) {
                        document.getElementById('selectNew').value = 0;
                        var BookId = document.getElementById('selectOld').value;
                        var xmlhttp = new XMLHttpRequest();
                        xmlhttp.onreadystatechange = function () {
                            alert(xmlhttp.readyState + " " + xmlhttp.status);
                            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                                document.getElementById('bibleDesc').innerHTML = xmlhttp.responseText;
                                document.getElementById('showChapter').innerHTML = "باب1 ";
                                window.history.pushState(null, null, 'bible.php?bookid=' + BookId + "&chapterid=1");
                            }else{alert('notready');}
                            xmlhttp.open("GET", "verse.php?bookid=" + BookId + "&chapterid=1", true);
                            xmlhttp.send();
                        }
                    } else {
                        document.getElementById('selectOld').value = "";
                    }
                    document.getElementById('selectedBook').value = obj.value;
                }
  پاسخ
تشکر شده توسط :


پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان