[英]PHP / JS - Echo Js function Notification after PHP curl post
我试图显示一个Javascript函数,该函数包含我的PHP Curl发布后的警报/通知。
任何想法如何使它工作?
我的Javascript:
<script>
$('body').pgNotification({
style:'bar',
message: 'added',
position:'top',
type:'success',
timeout:'6000'
}).show();
</script>
我的PHP:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'www.site.com');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'parameters to pass');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookiefile';
$response = curl_exec($ch);
curl_close($ch);
?>
现在,我想在PHP curl发布完成后显示Javascript通知。
可悲的是,我不能简单地使用echo 'HTMLCODE';
显示通知。 我需要其中的超时功能。
我感谢各种帮助。
期望您没有通过AJAX
调用CURL
。 如果CURL
响应是您想要的,只需回显您的javascript函数。
Java脚本
function showNotification(){
$('body').pgNotification({
style:'bar',
message: 'added',
position:'top',
type:'success',
timeout:'6000'
}).show();
}
的PHP
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'www.site.com');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'parameters to pass');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookiefile';
$response = curl_exec($ch);
curl_close($ch);
if($response == 'whatever it should return'){
echo "
<script>
// Run this if page is loaded
// Probably using jQuery?
$(document).ready(function(){
showNotification();
});
</script>";
}
?>
function test() { $('body').pgNotification({ style:'bar', message: 'added', position:'top', type:'success', timeout:'6000' }).show(); }
<?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'www.site.com'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, 'parameters to pass'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookiefile'; $response = curl_exec($ch); curl_close($ch); echo '<script>test();</script>'; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.