weixin_33709219 2014-06-12 05:36 采纳率: 0%
浏览 67

JSON不返回对象

JSON Array not returning object instead returning value

HI friends i have a scenario wherein the user enters his memberid i do a jquery ajax with memberid and fetch the details related to him and put it in a textbox ,

It was working fine on my server when the code is deployed to other server i'm not getting the result

the code is as shown below

  1. createaccount.php

                <title>Century Club</title>
            <link href='http://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'>
            <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
    
    
                <link href="css/century-club.css" rel="stylesheet">
    
    
    
            <script src="js/jquery-1.4.2.min.js" type="text/javascript" charset="utf-8"></script>
    
    
                <script type="text/javascript">
    
    
                    function check()
                    {       
    
                        var mid = $("#memberid").val();
    
    
                        var dataString = "mid=" + mid ;
    
                            $.ajax({  
                                type: "POST",  
                                url: "getdetails2.php",  
                                datatype: 'json',
                                data: dataString,
                                beforeSend: function() 
                                {
                                    $('#process').html($('#status').html());
                                },  
                                success: function(data)
                                {
                                        $('#process').html('');
                                         alert(data);
                                        $.each(data, function (i,member) {
                                            $("#name").val(member.name);
    
                                        });
    
                                }   
                            });
    
                    }//End of SecureLogin 
    
    
                </script>
    
              </head>
    
              <body>
                <div class="container">
    
    
                        <div class="menu">
                        <span class="nav_top"></span>
                        <div class="clr"></div>
                            <nav id="menu-wrap">    
    
            </nav>
                        </div>
                </div>  
    
                 <div class="container">
                    <div class="register">
                     <div class="row">
                    <div class="col-xs-12 col-md-9">
                         <div class="matter"><div style="clear:both; height:15px;"></div>
                <center><h1>Create New Account</h1></center>
                <div style="clear:both; height:8px;"></div>
    
                     <div class="join-club">
                        <h4 class="join-heading">Century Club - Create Account <br><span class="legend"><font color="#FF0000"><font class="red"> *</font></font> indicates a mandatory field</span></h4>
    
    
                <div align="center" id="status" style="display:none">
                        Just Wait a Moment..</div>
                        <div id="process" class="process"></div>          
            <form id="register" name="register"   method="POST">            
                 <table class="join-members" width="100%" style="margin:10px 0 0 0; ">
                    <tbody>
    
                    <tr>
                        <td width="47%"><span>User Name (Membership Account No.)<font class="red"> *</font></span>
                            <p>(Example : abcd1234)</p>
                        </td>
                        <td colspan="2">
                            <input   type="text" name="memberid" id="memberid"  Maxlength="15"
                            value="<?php if(!empty($memberid)) echo $memberid;?>" autocomplete="off"  style="width: 95%;
                        padding: 6px;" class="email2"  onblur="check();"   /></td>
                    </tr>
    
                    <tr>
                    <td><span>Name <font class="red"> *</font></span></td>
    
                        <td colspan="2"><input  type="text" name="name" id="name"  readonly
                        value="<?php if(!empty($name)) echo $name;?>"  class="email"/></td>
                    </tr>
    
                    <tr>
                        <td >
                        </td>
                        <td colspan="2">  <input type="submit"   name='submit_req' value="Submit" class="button"  style="margin:0"  /> </td>
                    </tr>
                    </tbody>
                 </table>
            </form>
    
                  </div>
                </div>
                    </div>
                    </div>
                        <div class="clr"></div>
                    </div>
    
                    </div>
                 </div>
    
               </body>
            </html>
    

JSon response file getdetails2.php

 <?php
    include("connection.php");
    $mid=trim($_POST['mid']);

    $query="Select member_id,member_name,office_number,mobile_number,Residence_number from cm_details where member_id='$mid'";
    $data=mysqli_query($dbc,$query);

    //while loop starts here buddy
    while($row=mysqli_fetch_array($data))
        {
            $mid=$row[0];
            $mname=$row[1];
            $rows[] = array("name" => $mname);
        }//end of while loop here

    @header("Content-type: application/json");
    echo json_encode($rows);
?>

As far as the analysis made it is treating the JSON response as an object in my server where the code works fine but in the other server it doesnt treate it as an object

And one more error i noticed is

 Uncaught TypeError: Cannot use 'in' operator to search for '182' in
 [{"name":"SRI.M.S.ASHOKKUMAR","mobile":"9845901242","rescode":"080","resnum":"25253602","rescode1":"","resnum1":"","offcode":"","offnum":"","offcode1":"","offnum1":"","mobile1":""}]

Thats all i could do guys i feel like JSON is not identified by the server something like that help me guys expecting your answers as soon as possible

  • 写回答

1条回答 默认 最新

  • weixin_33690367 2014-06-12 05:52
    关注

    What kind of error / problems are you seeing if any? Also maybe use header instead of @header so that you can see error messages.

    have you checked your php version on the server that isnt working? json_encode / json_decode were introduced in php 5.2.

    If that's the problem you might need to use something like jsonwrapper.

    评论

    报告相同问题?

    悬赏问题

    • ¥15 我不明白为什么c#微软的官方api浏览器为什么不支持函数说明的检索,有支持检索函数说明的工具吗?
    • ¥15 ORBSLAM2框架跑ICL-NUIM数据集
    • ¥15 在我想检测ros是否成功安装时输入roscore出现以下
    • ¥30 老板让我做一个公司的投屏,实时显示日期,时间,安全生产的持续天数,完全没头绪啊
    • ¥15 Google Chrome 所有页面崩溃,三种解决方案都没有解决,我崩溃了
    • ¥20 使用uni-app发起网络请求,获取重定向302返回的cookie
    • ¥20 手机外部浏览器拉起微信小程序支付 (相关搜索:微信小程序)
    • ¥20 怎样通过一个网址找到其他同样模版的网址
    • ¥30 XIAO esp32c3 读取FDC2214的数据
    • ¥15 在工控机(Ubuntu系统)上外接USB蓝牙硬件进行蓝牙通信