简体   繁体   English

PHP / JS-PHP curl发布后的Echo Js函数通知

[英]PHP / JS - Echo Js function Notification after PHP curl post

I'm trying to show a Javascript function, which contains a alert/notification after my PHP Curl post went through. 我试图显示一个Javascript函数,该函数包含我的PHP Curl发布后的警报/通知。

Any idea how to get this working? 任何想法如何使它工作?

My Javascript: 我的Javascript:

<script>
    $('body').pgNotification({
        style:'bar',
        message: 'added',
        position:'top',
        type:'success',
        timeout:'6000'
    }).show();
</script>

My PHP: 我的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);
?>

Now I want to show the Javascript Notification after the PHP curl post is done. 现在,我想在PHP curl发布完成后显示Javascript通知。

Sadly I can't simply use a echo 'HTMLCODE'; 可悲的是,我不能简单地使用echo 'HTMLCODE'; to show a notification. 显示通知。 I need the timeout function in it. 我需要其中的超时功能。

I appreciate every kind of help. 我感谢各种帮助。

Expecting that you are not calling CURL through AJAX . 期望您没有通过AJAX调用CURL Just echo your javascript function if CURL response is what you want it to be. 如果CURL响应是您想要的,只需回显您的javascript函数。

Javascript Java脚本

function showNotification(){
  $('body').pgNotification({
      style:'bar',
      message: 'added',
      position:'top',
      type:'success',
      timeout:'6000'
  }).show();
}

PHP 的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM