Ajax call not returning anything

t3rror

New Member
i am calling a webservice when the page is loaded ie,the code for that is below which is included at the top of addmachine.php\[code\]<?phpsession_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->location[0]->name; $bui[]=$each->location[0]->building[0]; $org[]=$each->name; } ?>\[/code\]the response of the web service is a json is as follows \[code\][{"location":[{"building":["Default Building"],"name":"Default Location"}],"name":"Default Organization"},{"location":[{"building":["test_loc1_building1","test_loc1_building2"],"name":"test location1"},{"building":["test_loc2_building2"],"name":"test location2"}],"name":"test Organization"}] \[/code\]i have decoded the json and moved as options in the drop down menu for organisations ,locations, and buildings,then after selecting organisation,building and location from the drop down a web service need to called using ajax \[code\] <form name="theForm" method="post" action="addmachine.php" enctype="multipart/form-data" onSubmit="return validate();"> <label for="orgname">Organisation Name</label> <select style="width: 305px;text-align:left ;" name="category_id" id="category_id"> <option value="">Select</option> <?php foreach($org as $key=>$val){?> <option value="http://stackoverflow.com/questions/15900671/<?php echo $val; ?>"><?php echo $val;?></option> <?php } ?> </select> <p> <label name="location">Location</label> <select style="width: 305px;" name="category_id1" id="category_id1"> <option value="">Select</option> <?php foreach($loc as $key=>$val){?> <option value="http://stackoverflow.com/questions/15900671/<?php echo $val; ?>"><?php echo $val; ?></option> <?php }?> </select> </p> <p> <label for="building">Building</label> <select style="width: 305px" name="category_id2" id="category_id2"> <option value="">Select</option> <?php foreach($bui as $key=>$val){?> <option value="http://stackoverflow.com/questions/15900671/<?php echo $val; ?>"><?php echo $val; ?></option> <?php } ?> </select> </p> <label for="entr/exi">Entrance/Exit</label> <select style="width: 305px;text-align:left ;" name="building" id="category_id1" onkeypress="return ajax();"> <option value="">Select</option> <?php foreach($org as $key=>$val){?> <option value="http://stackoverflow.com/questions/15900671/<?php echo $val; ?>"><?php echo $val;?></option> <?php } ?> </select> <p> <label for="type">Type</label> <input type="text" name="type" placeholder="enter your work station"/> <label for="name">Name</label> <input type="text" name="workstnname" placeholder="enter your work station" onkeypress="return onKeyPressBlockNumbers(event);"> <label for="description">Description</label> <textarea name="description" style="height:150px;width:300px;"></textarea> <label for="machinetype">Machine Type</label> <select style="width: 305px;text-align:left;" name="machinetype"> <option value="">Select</option> <option value="http://stackoverflow.com/questions/15900671/kiosk">kiosk</option> <option value="http://stackoverflow.com/questions/15900671/workstation">workstation</option> </select> <p> <input type="submit" name="submit" value="http://stackoverflow.com/questions/15900671/Submit"> </p> </form>\[/code\]for that i have called a function ajax(); on keypress of the field entrance/exit.i have made the ajax call as follows here i wish to execute another php page called ajaxweb.php my ajax code is as follows inside the script tag of the page addmachine.php\[code\] $.ajax({ type: "GET", //GET or POST or PUT or DELETE verb url:ajaxweb.php, // Location of the service data: "", //Data sent to server contentType: "json", // content type sent to server dataType: "json", //Expected data format from server processdata: true, //True or False success: function (json) {//On Successful service call var result = json.name; $("#dvAjax").html(result); }, error: ServiceFailed // When Service call fails }); return false; });\[/code\]ajaxweb.php where the selected organisation ,location and building is given to web service to give a return on same page but its not working also i would like to know how can i send theat response to addmachine.php page.\[code\] <?php session_start(); $org=$_POST['category_id']; $loc=$_POST['category_id1']; $bui=$_POST['category_id2']; $addmachine=array('org_name'=>$org,'loc_name'=>$loc,'building_name'=>$bui ); echo json_encode($addmachine); $url='webservice url'; $data="http://stackoverflow.com/questions/15900671/$addmachine"; echo("Input to Server : ".$data."\n"); $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($addmachine)); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); $response= curl_exec($ch); echo('\n'."Server response : \n \n".$response); curl_close($ch); ?>\[/code\]Hope some one would helpthank you
 
Top