javascript - error in passing parameters to php file using ajax -
i doing project records video ip photographic camera . used ajax run programme end records video using code process.php file. trying create programme more dynamic each user , facing problem passing parameters next page i.e record.php 2 parameters want pass email & url tried next way pass variables process.php using ajax link :
xmlhttp.open('get','http://localhost/ipcam/process.php?sh=1&url=<?php echo $url ?>&email=<?php echo $email ?>',true);
here finish script. can suggest me proper way write above url work dynamically.
<script type="text/javascript"> function st() { if (window.xmlhttprequest) { xmlhttp=new xmlhttprequest(); } else { xmlhttp=new activexobject('microsoft.xmlhttp'); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { alert('stored'); } } xmlhttp.open('get','http://localhost/ipcam/process.php?sh=1&url=<?php echo $url ?>&email=<?php echo $email ?>',true); xmlhttp.send(); settimeout('st()',5000); } </script>
try url encoding php vars like:
xmlhttp.open('get','http://localhost/ipcam/process.php?sh=1&url=<?php echo urlencode($url) ?>&email=<?php echo urlencode($email); ?>',true);
i have used pattern before. assumes page containing javascript above code .php file having. although improve way design application include javascript external file in case should like:
$export_vars = array('url' => $url, 'email' => $email); echo '<script type="text/javascript">' . 'var userdata = ' . json_encode($export_vars) . ";" . '</script>';
while initial javascript function must rewritten as:
function st(url, email)
php javascript ajax curl urlencode
No comments:
Post a Comment