Page 13 - ChatBot-59122201009
P. 13

9     $username  = "1dbaa6dd-68fc-49a2-bf19-34f6bb01ae56";
                 10     $password = "2qkv5Hg0jSmQ";
                 11
                 12     $ch = curl_init();
                 13     $json = ['input'=> ['text'=> $_POST['meg']],"alternate_intents"=>
                 14 true];
                 15     curl_setopt($ch, CURLOPT_URL, $url);
                 16     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                 17     curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
                 18
                 19     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
                 20     curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($json));
                 21     curl_setopt($ch, CURLOPT_HTTPHEADER,
                 22     array('Content-Type:application/json',
                 23         'Content-Length: ' . strlen(json_encode($json)))
                 24     );
                 25     $output = curl_exec($ch);
                 26     $info = curl_getinfo($ch);
                 27     $teee = ['test'=>'yee'];
                 28     echo $output;
                 29     //return $_POST['meg'];
                 30
                    }else{
                        return 'null';
                    }
                    ?>




               2. Code หน้านี้มีไว้รับข้อมูลจาก User เพื่อจะส่งค่าไปยัง Test2.php


                  1 <link rel="stylesheet" href="./chatbot/styleCss.css">
                  2 <div id="test">
                  3     <ul>
                  4
                  5     </ul>
                  6 </div>
                  7     <input type="text" name="meg" id="meg">
                  8     <button type="button" id='submit' >send</button>
                  9 <script>
                 10     var msgT;
                 11     $(document).ready(function(){
                 12         $("#submit").click(()=> {
                 13             $("#test ul").append("<li
                 14 class='user'>"+$("#meg").val()+"</li>")
                 15             $.ajax({
                 16             method: "POST",
                 17             url: "chatbot/test2.php",
                 18             data: { meg: $("#meg").val() },
                 19             dataType : 'JSON',
                 20             })
   8   9   10   11   12   13   14   15