[英]error in passing parameters to php file using ajax
I am doing a project which records video from Ip camera . 我正在做一个从ip摄像机录制视频的项目。 I used ajax to run my program back end which successfully records video using code from process.php file.
我使用ajax运行我的程序后端,该程序使用process.php文件中的代码成功记录了视频。 However i am trying to make program more dynamic for each user and I am facing problem passing parameters to my next page ie record.php the 2 parameters i want to pass are email & url i tried the following way to pass variables to my process.php using ajax link :
但是,我试图使每个用户的程序更动态,我面临着将参数传递给我的下一页的问题,即record.php我想传递的2个参数是电子邮件和url,我尝试了以下方式将变量传递给我的过程。 php使用ajax链接:
xmlhttp.open('GET','http://localhost/IPCAM/process.php?sh=1&url=<?php echo $url ?>&email=<?php echo $email ?>',true);
Here is the complete script. 这是完整的脚本。 Can anyone suggest me proper way to write the above url to 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 your php vars like: 尝试使用URL编码您的php var,例如:
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. 我以前使用过模式。 This assumes that the page containing the JavaScript like the above code is actually a .php file having.
假设包含上述代码的JavaScript的页面实际上是一个.php文件。 Although a better way to design your application would be to include javascript as an external file in that case you should do something like:
尽管设计应用程序的更好方法是在这种情况下将javascript作为外部文件包含在内,但您应该执行以下操作:
$export_vars = array('url' => $url, 'email' => $email);
echo '<script type="text/javascript">' .
'var userData = ' . json_encode($export_vars) . ";" .
'</script>';
while your initial javascript function must be rewritten as: 而您的初始javascript函数必须重写为:
function st(url, email)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.