我正在尝试显示一个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卷发后显示Javascript通知。
可悲的是,我不能简单地使用echo 'HTMLCODE';
来显示通知。我需要超时功能。
我感谢各种帮助。
答案 0 :(得分:0)
期望您没有通过CURL
致电AJAX
。如果CURL
响应符合您的要求,请回复您的javascript函数。
<强>的Javascript 强>
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>";
}
?>
答案 1 :(得分:0)
function test() {
$('body').pgNotification({
style:'bar',
message: 'added',
position:'top',
type:'success',
timeout:'6000'
}).show();
}
&#13;
<?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>';
?>
&#13;