Monday, January 7, 2013

send request and get response using php json and curl client and server page

stp-1 create you client page which can send the request to server page
like sendclientrequest.php and paste below code

<?php
$url = "http://127.0.0.1/test/ReceiveRequestReturnResponse.php";
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'xmlstr='.$xmlStr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$data = curl_exec($ch);
$row=json_decode($data,true);
foreach($row as $fields){
echo $fields;
}
?>
---------------receive request and send response using JSON AND CLIENT curl-----------------------
create ReceiveRequestReturnResponse.php get request and return respose in json curl
<?php
$row=array('id'=>2,'name'=>'bikash','address'=>'delhi');
echo json_encode($row);
?>

click to show div and outside click to hide div

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script language="javascript">
$(document).mouseup(function (e)
{
    var container = $(".form_wrapper");

    if (container.has(e.target).length == 0)
    {
        container.hide();
    }
});
function showdiv(){

document.getElementById('form_wrapper').style.display='block';

}
</script>
<div class="form_wrapper" id="form_wrapper" style="display:none">
show div and your menu
</div>
<a  href="javascript:;" onClick="showdiv();">show</a>

i hope its help