在PHP中从JSON中提取值

时间:2014-11-04 22:57:21

标签: php ajax json

如何从此输出中仅获得79? {"成功":""," htmlResponse":79}

我将此作为JSON返回 我正在调用一个php函数来通过ajax获取值,这是我警报的输出

   $.ajax({
          url: urlJSON,
          success:function(data){
                alert(data);

            }

<table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
   <tr>
     <th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined variable: success in C:\Apache24\htdocs\project\getPercentageCompleted.php on line <i>7</i></th>
  </tr>
  <tr>
     <th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th>
  </tr>

  <tr>
     <td bgcolor='#eeeeec' align='center'>1</td>
     <td bgcolor='#eeeeec' align='center'>0.0040</td>
     <td bgcolor='#eeeeec' align='right'>145240</td>
     <td bgcolor='#eeeeec'>{main}( )</td>
     <td title='C:\Apache24\htdocs\tool\index.php' bgcolor='#eeeeec'>..\index.php<b>:</b>0</td>
  </tr>
  <tr>
     <td bgcolor='#eeeeec' align='center'>2</td>
     <td bgcolor='#eeeeec' align='center'>0.0250</td>
     <td bgcolor='#eeeeec' align='right'>347960</td>
     <td bgcolor='#eeeeec'>require_once( <font color='#00bb00'>'C:\Apache24\htdocs\project\actions\getPercentageCompleted.php'</font> )</td>
     <td title='C:\Apache24\htdocs\project\index.php' bgcolor='#eeeeec'>..\index.php<b>:</b>39</td>
  </tr>

{"success":"","htmlResponse":79}

1 个答案:

答案 0 :(得分:1)

$.ajax({
      url: urlJSON,
      success:function(data){
            var myObject=JSON.parse(data);
            alert(myObject.htmlResponse);

        }

但只要您使用jQuery,为什么不使用$.getJSON()?更容易。