Monday, January 7, 2013

div open in window.open using javascript


<script language="JavaScript" type="text/javascript">
<!--
function doWin(){
var orig_div_cont=document.getElementById("showcontent").innerHTML;
var myWin=window.open("","myWin","menubar,scrollbars,left=30px,top=40px,height=400px,width=600px");
myWin.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">'+
'<html><head><title>My Window</title></head><body><div id="dest_div">'+
'Some original division content. <br /></div></body></html>');
myWin.document.close();
myWin.document.getElementById("dest_div").innerHTML+=orig_div_cont;
}
//-->
</script>


<div id="showcontent">di content show in window pop</div>
<a href="javascript:;" onclick="doWin();">open</a>

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);
?>