简体   繁体   English

Ajax Internet Explorer onchange

[英]ajax internet explorer onchange

My ajax script for loading the second select box, works in firefox and chrome, but internt explorers cant handle it. 我的用于加载第二个选择框的ajax脚本可以在Firefox和chrome中使用,但是Internt资源管理器无法处理它。 I call the onChange function from my select box and give the value from the select box to the function. 我从选择框调用onChange函数,并将选择框的值提供给函数。

Code: 码:

function getXMLHTTP() 
{
var xmlhttp;

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

return xmlhttp;
}

function getType(categoryName) 
{       

    var strURL="includes/get.php?c="+categoryName+"&sid="+Math.random();
        var req = getXMLHTTP();

        if (req) {

                req.onreadystatechange = function() {
                        if (req.readyState == 4) {
                                // only if "OK"
                                if (req.status == 200)
                                    {document.getElementById('type').innerHTML=req.responseText;                        
                                } else {
                                        alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                                }
                        }               
                }           
                req.open("GET", strURL, true);
                req.send(null);
        }       
}

My second question is, is it possible to send the text between the options tag instead of the value in the options tag? 我的第二个问题是,是否可以在选项标签之间而不是选项标签中的值之间发送文本?

For your 1st question, I assume your if (req) returns false. 对于第一个问题,我假设您的if (req)返回false。 Which IE version are you using? 您正在使用哪个IE版本? Try to add debug codes in getXMLHTTP() function to start diagnosing the codes. 尝试在getXMLHTTP()函数中添加调试代码以开始诊断代码。 Try this solution provided by Microsoft: http://msdn.microsoft.com/en-us/library/ms537505(v=vs.85).aspx 尝试使用Microsoft提供的以下解决方案: http : //msdn.microsoft.com/zh-cn/library/ms537505(v=vs.85).aspx

I try not to repeat other's answer. 我尽量不重复别人的回答。 Here is the answer for obtaining text in selected option tag : Getting the text from a drop-down box 这是在选定的选项标签中获取文本的答案: 从下拉框中获取文本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM