Note that there are some explanatory texts on larger screens.

plurals
  1. POsend the php webservice json response to javascript
    text
    copied!<p>i would like to bring up the php web service response in json to javascript which is obtained from a php web service call here is my code</p> <pre><code>&lt;?php session_start(); $url='webservice url'; $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($useridofuser)); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); $response= curl_exec($ch); //echo('\n'."Server response : \n \n".$response); curl_close($ch); //parsing the json response from server $jsonde="$response"; $_SESSION['json']=$jsonde; $org = array(); $loc = array(); $bui = array(); $items = json_decode($response); foreach( $items as $each ){ $loc[]=$each-&gt;location[0]-&gt;name; $bui[]=$each-&gt;location[0]-&gt;building[0]; $org[]=$each-&gt;name; } ?&gt; </code></pre> <p>here i obtain organisation names in $org,$bui contain buildings ,and $loc contain locations i have a form below this code</p> <pre><code> &lt;sript&gt; var json = "&lt;?php echo $response ?&gt;"; alert(json); &lt;/script&gt; &lt;form&gt; &lt;label for="orgname"&gt;Organisation Name&lt;/label&gt; &lt;select style="width: 305px;text-align:left ;" name="category_id" id="category_id"&gt; &lt;option value=""&gt;Select&lt;/option&gt; &lt;?php foreach($org as $key=&gt;$val){?&gt; &lt;option value="&lt;?php echo $val; ?&gt;"&gt;&lt;?php echo $val;?&gt;&lt;/option&gt; &lt;?php } ?&gt; &lt;/select&gt; &lt;p&gt; &lt;label name="location"&gt;Location&lt;/label&gt; &lt;select style="width: 305px;" name="category_id1" id="category_id1" onchange="ajax(this);"&gt; &lt;option value=""&gt;Select&lt;/option&gt; &lt;/select&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="building"&gt;Building&lt;/label&gt; &lt;select style="width: 305px" name="category_id2" id="category_id2"&gt; &lt;option value=""&gt;Select&lt;/option&gt; &lt;/select&gt; </code></pre> <p></p> <p>in the organisations i would like to compare the value i have selected from combo box for organisation with the json array returened from the php web service and return the object that contain that particaular organisation,really my question is how can i store a json array into a javascript variable or some thing . thank you </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload