Bonjour,

Je souhaite afficher sur une page un bot (j'utilise pour cela le logiciel libre Program-O). Voici la page complète, avec du Javascript pour rafraichir uniquement la div de conversation :

Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE html>
<!--[if IE 8]> 		<html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
 
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
 
  <link rel="shortcut icon" href="favicon.ico"  type="image/x-icon">
 
  <link rel="stylesheet" href="template/css/foundation.css">
  <link rel="stylesheet" href="template/css/foundation-icons.css">
  <script src="template/js/vendor/custom.modernizr.js"></script>
 
<!-- flux rss -->
  <script type="text/javascript" src="template/js/jquery.js" ></script>
  <script type="text/javascript" src="template/js/FeedEk.js"></script>
 
<script type="text/javascript">
function refresh() {
$.ajax({
    url: "./traitement4.php",
    success:
        function(retour){
        $("#response").html(retour); 
    }
});
 
}
setInterval("refresh()", 1000)
</script>
 
<style type="text/css">
      h3 {
        text-align: center;
      }
      .user_name {
        color: rgb(16, 45, 178);
      }
      .bot_name {
        color: rgb(204, 0, 0);
      }
 
</style>  
 
<script type="text/javascript" >
     $(document).ready(function() {
        $('#talkform').submit(function(e) {
          e.preventDefault();
          user = $('#say').val();
          $('.usersay').text(user);
          formdata = $("#talkform").serialize();
          $('#say').val('')
          $('#say').focus();
          $.post('<?php echo $url ?>', formdata, function(data){
            var b = data.botsay;
            var usersay = data.usersay;
            if (user != usersay) $('.usersay').text(usersay);
            $('.botsay').html(b);
          }, 'json');
          return false;
        });
      });
</script>
 
</head>
<body>
 
<?php include("template/inc/header.inc.php"); ?>
 
<!-- Main Page Content and Sidebar -->
 
<div class="row">
 
<!-- Main Blog Content -->
<div class="large-9 columns">
 
<article>
<div class="text-justify">
<br>
<div class="row">
<div class="large-11 columns">
<h1>A propos</h1>
<br>
 
<p>
<body onload="document.forms[0].say.focus();">
    <h3>Posez vos questions</h3>
 
<div id="chat">
 
<p>Le site : </p>
<div class="bot"> 
</div><br>
<p>Le visiteur : </p>
<div class="usersay"> </div><br>
 
    <img src="live.png">
    <form accept-charset="utf-8" id="talkform" method="get" action="<?php echo $_SERVER['PHP_SELF'] ?>">
      <p>
        <input type="text" name="say" id="say" />
        <input id="bot_id" type="hidden" name="bot_id" value="<?php echo $bot_id ?>">
        <input id="convo_id" type="hidden" name="convo_id" value="<?php echo $convo_id ?>">
        <input id="format" type="hidden" name="format" value="xml">
	<button id="envoie">Parler</button>
      </p>
    </form>
</div>
 
</p>
 
</div>
</div>
</div>
</article>
 
</div>
 
<!-- End Main Content -->
 
<!-- Sidebar -->
<?php include("template/inc/sidebar.inc.php"); ?>
 
<!-- End Sidebar -->
</div>
 
<!-- End Main Content and Sidebar -->
 
<?php include("template/inc/footer.inc.php"); ?>
 
</body>
</html>

Et la la page traitement4.php :

Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/***************************************
  * http://www.program-o.com
  * PROGRAM O
  * Version: 2.3.1
  * FILE: index.php
  * AUTHOR: Elizabeth Perreau and Dave Morton
  * DATE: 07-23-2013
  * DETAILS: This is the XML GUI interface for Program O
  ***************************************/
 
  // $display = 'Make sure that you edit this file to change the value of $url below to reflect the correct address, and to remove this message.';
  $url = 'http://mon-site.fr/chatbot/conversation_start.php';
  $display_template = <<<end_display
      <span class="user_name">[user_name]: </span><span class="user_say">[input]</span><br>
      <span class="bot_name">[bot_name]: </span><span class="bot_say">[response]</span><br>
 
end_display;
 
  $post_vars = (!empty($_POST)) ? filter_input_array(INPUT_POST) : array();
  $get_vars = (!empty($_GET)) ? filter_input_array(INPUT_GET) : array();
  $request_vars = array_merge($get_vars, $post_vars);
  $convo_id = (isset ($request_vars['convo_id'])) ? $request_vars['convo_id'] : get_convo_id();
  $bot_id = (isset ($request_vars['bot_id'])) ? $request_vars['bot_id'] : 2;
  if (!empty ($request_vars))
  {
    $options = array(
      CURLOPT_USERAGENT => 'Program_O_XML_API',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POST => true,
      //CURLOPT_CONNECTTIMEOUT => 3,
    );
    $ch = curl_init($url);
    curl_setopt_array($ch, $options);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request_vars);
    $data = curl_exec($ch);
    curl_close($ch);
    $xml = new SimpleXMLElement($data);
    $display = '';
    $success = $xml->status->success;
    if (isset($xml->status->message))
    {
      $message = (string) $xml->status->message;
      $display = 'There was an error in the script. Message = ' . $message;
    }
 
    else
    {
      $user_name = (string) $xml->user_name;
      $bot_name = (string) $xml->bot_name;
      $chat = $xml->chat;
      $lines = $chat->xpath('line');
      foreach ($lines as $line)
      {
        $input = (string) $line->input;
        $response = (string) $line->response;
        $tmp_row = str_replace('[user_name]', $user_name, $display_template);
        $tmp_row = str_replace('[bot_name]', $bot_name, $tmp_row);
        $tmp_row = str_replace('[input]', $input, $tmp_row);
        $tmp_row = str_replace('[response]', $response, $tmp_row);
        $display .= $tmp_row;
 
      }
    }
  }
 
  function get_convo_id()
  {
    if (isset($_COOKIE['Program_O_XML_API'])) $convo_id = $_COOKIE['Program_O_XML_API'];
    else
    {
      session_name('Program O XML GUI');
      session_start();
      $convo_id = session_id();
      session_destroy();
    }
    return $convo_id;
 }
?>

La page s'actualise bien et affiche ce que le visiteur tape, mais le problème c'est que je n'arrive pas à afficher la réponse du bot. Y a-t-il un moyen de tester l'envoie de données entre la page HTML et la page PHP, et vérifier le retour ?

Si quelqu'un pouvait me renseigner svp, merci d'avance,
Très cordialement,

ANDRE Ani