[英]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.