Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.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数组-jQuery引用问题_Php_Jquery_Ajax_Json - Fatal编程技术网

PHP数组-jQuery引用问题

PHP数组-jQuery引用问题,php,jquery,ajax,json,Php,Jquery,Ajax,Json,我有以下几点: 1) echo json_encode(array('message' => 'Invalid Login Details: '.$user)); 我还有以下几点: 2) $row = mysql_fetch_assoc($result); echo(json_encode($row)); 现在考虑下面的jQuery: $.ajax({ type: "POST", url: "get_login.php",

我有以下几点:

1) echo json_encode(array('message' => 'Invalid Login Details: '.$user));
我还有以下几点:

2) $row = mysql_fetch_assoc($result);
   echo(json_encode($row));

现在考虑下面的jQuery:

 $.ajax({
           type: "POST",
           url: "get_login.php",
           data: {username: getusername, password:getpassword, usertype:getusertype},
           dataType: "json",
           success: function(data) {
              $("#message_ajax").html("<div class='successMessage'>" + data.message +"</div>");
           }
        })
$.ajax({
类型:“POST”,
url:“get_login.php”,
数据:{用户名:getusername,密码:getpassword,用户类型:getusertype},
数据类型:“json”,
成功:功能(数据){
$(“#message_ajax”).html(“+data.message+”);
}
})
这在(1)中成功,但在(2)中不成功。这显然是因为jQuery需要一个包含消息变量的php响应。(2) 不符合这个…我不知道;我不知道如何使这项工作,因为我正在使用不同的方法来创建阵列

如何使php中的$row与jQuery中的data.message兼容

试试看:

$data = array();
$data["message"] = "Valid request";
$data["row"] = mysql_fetch_assoc($result);
   echo(json_encode($data));
消息=行:

$data = array();
$data["message"] = mysql_fetch_assoc($result);
   echo(json_encode($data));
或双线解决方案(受val启发):

尝试:

消息=行:

$data = array();
$data["message"] = mysql_fetch_assoc($result);
   echo(json_encode($data));
或双线解决方案(受val启发):

试一试

然后,为了回答你关于评论的第二个问题,类似的东西可以显示信息

 $.ajax({
           type: "POST",
           url: "get_login.php",
           data: {username: getusername, password:getpassword, usertype:getusertype},
           dataType: "json",
           success: function(data) {
              $("#message_ajax").html("<div class='successMessage'>" + data.message +"</div>");
              var html = '';
              for(var i = 0; i<data.result.length;i++){
                 html +='<div>'+data.result[i].fname+'</div>';
               }
              $('#result').html(html);
           }
        })
$.ajax({
类型:“POST”,
url:“get_login.php”,
数据:{用户名:getusername,密码:getpassword,用户类型:getusertype},
数据类型:“json”,
成功:功能(数据){
$(“#message_ajax”).html(“+data.message+”);
var html='';
对于(var i=0;iTry

然后,为了回答你关于评论的第二个问题,类似的东西可以显示信息

 $.ajax({
           type: "POST",
           url: "get_login.php",
           data: {username: getusername, password:getpassword, usertype:getusertype},
           dataType: "json",
           success: function(data) {
              $("#message_ajax").html("<div class='successMessage'>" + data.message +"</div>");
              var html = '';
              for(var i = 0; i<data.result.length;i++){
                 html +='<div>'+data.result[i].fname+'</div>';
               }
              $('#result').html(html);
           }
        })
$.ajax({
类型:“POST”,
url:“get_login.php”,
数据:{用户名:getusername,密码:getpassword,用户类型:getusertype},
数据类型:“json”,
成功:功能(数据){
$(“#message_ajax”).html(“+data.message+”);
var html='';

对于(var i=0;i我相信您没有来自
mysql\u fetch\u assoc
$row['message']
。 在
json\u encode
之前,必须明确定义数组上的
消息

$row = mysql_fetch_assoc($result); $row['message'] = 'Hello '.$row['username']; echo(json_encode($row)); $row=mysql\u fetch\u assoc($result); $row['message']=“你好”。$row['username']; echo(json_编码($row));
我相信您没有来自mysql的
$row['message']
\u fetch\u assoc
。 在
json\u encode
之前,必须明确定义数组上的
消息

$row = mysql_fetch_assoc($result); $row['message'] = 'Hello '.$row['username']; echo(json_encode($row)); $row=mysql\u fetch\u assoc($result); $row['message']=“你好”。$row['username']; echo(json_编码($row));
echo json_encode(数组('message'=>'无效登录详细信息:'$user));
错误,靠近
$user
,因为它将显示一个php文件error@Dogbert-$row包含关系中的元组(即用户详细信息-fName、lName、e-mail…
echo json_encode(数组('message'=>'无效登录详细信息:'$user));
错误,靠近
$user
,因为它将显示一个php文件error@Dogbert-$row包含一个关系的元组(即用户详细信息-fName、lName、e-mail…),很好,所以它可以工作…但它显示[Object]->如何让它显示实际的字符串值?
数据。消息将是一个对象。如果要显示内容,必须迭代其属性。很好,这样可以工作…但它显示[object]->如何使其显示实际字符串值?
数据。消息将是一个对象。如果要显示内容,必须迭代其属性。