Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于AJAX的Onchange()_Ajax_Onchange - Fatal编程技术网

用于AJAX的Onchange()

用于AJAX的Onchange(),ajax,onchange,Ajax,Onchange,我试图使用ajax显示文本框的onchange值。我的代码如下: ajaxquery.php <html> <head> <title>Changing textbox value based on dropdown list using Ajax and PHP</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <sc

我试图使用ajax显示文本框的onchange值。我的代码如下:

ajaxquery.php

<html>
<head>
<title>Changing textbox value based on dropdown list using Ajax and PHP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
//fuction to return the xml http object
function getXMLHTTP() { 
    var xmlhttp=false;  
    try{
        xmlhttp=new XMLHttpRequest();
    }
    catch(e)    {       
        try{            
            xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e){
            try{
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e1){
                xmlhttp=false;
            }
        }
    }

    return xmlhttp;
}



function getCurrencyCode(strURL)
{       
var req = getXMLHTTP();     
if (req) 
{
    //function to be called when state is changed
    req.onreadystatechange = function()
    {
        //when state is completed i.e 4
        if (req.readyState == 4) 
        {           
            // only if http status is "OK"
            if (req.status == 200)
            {                       
                document.getElementById('cur_code').value=req.responseText;                     
            } 
            else 
            {
                alert("There was a problem while using XMLHTTP:\n" + req.statusText);
            }
        }               
     }          
     req.open("GET", strURL, true);
     req.send(null);
}           
}
 </script>

 <body style="font: 12px Verdana, Arial, Helvetica, sans-serif;">
 <form style="text-align:center" method="post" action="" name="form1">
 <p>Country : <input type="text" name="country"  onChange="getCurrencyCode('code.php?country='+this.value)">
 </form>
 </body>
 </html>
<?php 
    $country=$_REQUEST['country'];
    echo $country;
?>

使用Ajax和PHP根据下拉列表更改文本框值
//函数返回xml http对象
函数getXMLHTTP(){
var xmlhttp=false;
试一试{
xmlhttp=新的XMLHttpRequest();
}
第(e)款{
试试{
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
捕获(e){
试一试{
xmlhttp=新的ActiveXObject(“Msxml2.xmlhttp”);
}
渔获物(e1){
xmlhttp=false;
}
}
}
返回xmlhttp;
}
函数getCurrencyCode(strURL)
{       
var req=getXMLHTTP();
如果(请求)
{
//状态更改时要调用的函数
req.onreadystatechange=函数()
{
//当状态完成时,即4
如果(req.readyState==4)
{           
//仅当http状态为“OK”时
如果(请求状态==200)
{                       
document.getElementById('cur_code')。value=req.responseText;
} 
其他的
{
警报(“使用XMLHTTP:\n“+req.statusText时出现问题”);
}
}               
}          
请求打开(“获取”,strURL,true);
请求发送(空);
}           
}
国家:
code.php

<html>
<head>
<title>Changing textbox value based on dropdown list using Ajax and PHP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
//fuction to return the xml http object
function getXMLHTTP() { 
    var xmlhttp=false;  
    try{
        xmlhttp=new XMLHttpRequest();
    }
    catch(e)    {       
        try{            
            xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e){
            try{
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e1){
                xmlhttp=false;
            }
        }
    }

    return xmlhttp;
}



function getCurrencyCode(strURL)
{       
var req = getXMLHTTP();     
if (req) 
{
    //function to be called when state is changed
    req.onreadystatechange = function()
    {
        //when state is completed i.e 4
        if (req.readyState == 4) 
        {           
            // only if http status is "OK"
            if (req.status == 200)
            {                       
                document.getElementById('cur_code').value=req.responseText;                     
            } 
            else 
            {
                alert("There was a problem while using XMLHTTP:\n" + req.statusText);
            }
        }               
     }          
     req.open("GET", strURL, true);
     req.send(null);
}           
}
 </script>

 <body style="font: 12px Verdana, Arial, Helvetica, sans-serif;">
 <form style="text-align:center" method="post" action="" name="form1">
 <p>Country : <input type="text" name="country"  onChange="getCurrencyCode('code.php?country='+this.value)">
 </form>
 </body>
 </html>
<?php 
    $country=$_REQUEST['country'];
    echo $country;
?>

该值未显示。我哪里做错了

另外,我对ajax完全陌生,对它一无所知。感谢您的帮助:)

国家/地区:
国家代码: