newBee
newBee

Reputation: 13

Extract value from JSON in PHP

How can I get only 79 from this output ? {"success":"","htmlResponse":79}

I'm returning this as JSON I'm calling a php function to get a value via ajax and this is the out put of my alert

   $.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}

Upvotes: 0

Views: 37

Answers (1)

Jonathan M
Jonathan M

Reputation: 17461

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

        }

But as long as you're using jQuery, why not use $.getJSON()? Much easier.

Upvotes: 1

Related Questions