Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery移动页面未响应事件_Javascript_Jquery_Html_Jquery Mobile - Fatal编程技术网

Javascript Jquery移动页面未响应事件

Javascript Jquery移动页面未响应事件,javascript,jquery,html,jquery-mobile,Javascript,Jquery,Html,Jquery Mobile,我正在尝试运行聊天应用程序,但我设置的单击侦听器不工作。当用户单击按钮时,不会发生任何事情。我的代码有问题吗 这是jquery/javascript脚本 <script> $(document).on("pageinit",function(event){ setInterval(update, 10000); setInterval(getMessage, 20000); $( "#submit" ).bind( "cli

我正在尝试运行聊天应用程序,但我设置的单击侦听器不工作。当用户单击按钮时,不会发生任何事情。我的代码有问题吗

这是jquery/javascript脚本

<script> 
    $(document).on("pageinit",function(event){
        setInterval(update, 10000);
        setInterval(getMessage, 20000);

        $( "#submit" ).bind( "click", function(event, ui) {
            //get message
            var msg_display = $("#msg").val();
            //get chat_id, if not set, display an alert of not able to send, please select chat member
            var chat_id = $("#chat_id").val();
            //get user_id
            var user = $("#user").val();
            if(chat_id != ""){
                //send message
              sendMessage(msg_display, chat_id, user);  
            }else{
                alert("Please select a user to chat with");
                $("#msg").val("");
            }
});

        $( "#m_on li" ).bind( "click", function() {
          var selected_member = $(this).html();
          window.location = 'chat.php?chat_mate=' + selected_member;
            //reload this page with the values of member to chat with
});



        function update() { 
     $.ajax({
         type: 'POST',
           url: "update.php",
           success: function(result){
               //all good.
           }
     })
 }
        function sendMessage(msg, msg_id, from){
           $.ajax({
         type: 'POST',
           url: "send_message.php",
           data: {msg:msg, msg_id:msg_id, from:from},
           success: function(result){
               if(result == "good"){
                   getMessage(msg_id);
               }else{
                   alert("Not able to send message " + result);
               }
           }
     })
        }

        function getMessage(msg_id){
           $.ajax({
         type: 'POST',
           url: "get_message.php",
           data: {msg_id:msg_id},
           dataType: "json",
           success: function(result){
               //all good.
               ///append to the chats.
               for(var i=0, i < result.length; i++){
                   $("#chats").append("<p>" + result[i]['message'] + "</p>" +
                                      "<p align=right>Sent by " + result[i]['sender'] + " at " + 
                                       result[i]['time'] + "</p>");
               }
               $("#msg").val("");
               $('#chats').animate({scrollTop:$('#chats').prop("scrollHeight")}, 500);
           }
     })
        }
});
</script>
我的html按钮是

<div id="chats"></div>
   <textarea cols="40" rows="8" name="msg" id="msg" placeholder="Message here..."></textarea>
   <input type="button" data-inline="true" id="submit" value="Submit">

pageinit与此有关吗?

对于var i=0,i
也许你应该试着多调试一点

非常感谢!!!删除逗号后,它终于起作用了。真不敢相信我从没见过它。干杯,伙计。