title: How to fetch data from database with json_encode of ajax
body: <p>I use ajax to fetch data from DB. And I chose alert(valData) in success function to test the data, but unlucky nothing return from 
  ajax. Then I tested </p>
  
  <pre><code>select contact from IDC WHERE id='5';
  </code></pre>
  
  <p>It works fine in mysql cmd line.</p>
  
  <p>Here is my js code:</p>
  
  <pre><code>var stNum = 5;
  $.ajax({
          dataType:'json',
          type:"POST",
          url:"get_ajax_csc.php",
          data:{stNum:stNum},
          success:function(data) 
          {
           var valData = data;
           alert(valData);
           $('#stContact').val(data.stCnt);
           $('#stPhone').val(data.stPho);
          }
        });
  </code></pre>
  
  <p>Here is my html code:</p>
  
  <pre><code>&lt;div class="divFir"&gt;
      &lt;label&gt;Contact:&lt;/label&gt;&lt;input type="text" id="stContact" &gt;&lt;br /&gt;
      &lt;label&gt;Phone:&lt;/label&gt;&lt;input type="text" id="stPhone" &gt;&lt;br /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here is get_ajax_csc.php code:</p>
  
  <pre><code>&lt;?php
  if(isset($_POST['stNum']))
  {   
   include("DB.php"); 
   $q=$_POST["stNum"];
   $sql="select contact,phone from IDC WHERE id='".$q."';";
   $sel = $conn-&gt;query($sql); 
  
   $arr = $sel-&gt;fetch(PDO::FETCH_ASSOC);
   $tmpArr = array(
      'stCnt'=&gt;$arr['contace'],
      'stPho'=&gt;$arr['phone']
      );
   echo json_encode($tmpArr);
   }
  
   if(isset($_POST['htmlCnt']))
  {   
  include("DB.php");
  $htcnt=stripslashes(".$_POST['htmlCnt'].");
  ........
  }
   ?&gt;
  </code></pre>
  
  <p>Here is DB.php code:</p>
  
  <pre><code>&lt;?php
  session_start();
  $pwd=$_SESSION['password'];
  $user=$_SESSION['user'];
  
  try 
  {
    $conn = new PDO('mysql:host=x.x.x.x;port=3306;dbname=hpc',$user,$pwd);
  }
  catch (PDOException $e)
  {
    echo "account or pwd wrong &lt;meta http-equiv='refresh' content='1;url=index.html'&gt;";
      exit;
  }  
  $conn-&gt;setAttribute(PDO::ATTR_ORACLE_NULLS, true);
  ?&gt;
  </code></pre>
  
  <p>It seems nothing wrong in my code, but I cann't fetch data from database</p>
  
  <p>I have found that stripslashes() made ajax return nothing. When I shielded this method (//stripslashes()), it worked fine. Why stripslashes can influence my ajax return data?</p>