在KEYUP AJAX调用()KEYUP、AJAX

2023-09-10 21:05:07 作者:恋爱是糖甜到忧伤

我有一个问题: 如果有人键入领域,这应该使文本字段为所有其他用户为只读,并显示味精,如人是打字,现在。

I have an issue: if someone is typing in field, this should make the text field for all other user as readonly and show msg like "someone is typing right now".

<div id="msg"></div>
<input type="text" name="field" id="field" />

$("#field").keyup(function (){
    var isTyping = $('#field').val();
    var data = 'result=' + isTyping;
    var msg = $('#msg');
    $.ajax({
        type: 'POST',
        url: "includes/control.php",
        data: data,
        cache: false,
        success: function(){  
           msg.html(html);
        }
    });
});

这是control.php:

And this is control.php:

if($_POST['result']){
    echo "someone is typing";
}

这工作就像是沙姆沙伊赫的点击()方法,而不是KEYUP()。

This work like a sharm for click() method but not for keyup().

感谢您的帮助。

推荐答案

奇怪的是,您要发送一个Ajax请求,只要用户类型而变化:

Strange that you are sending an ajax request whenever user types but change:

success: function(){  
    msg.html(html);
}

success: function(html){  
    msg.html(html);
}

因为你的 HTML 并没有定义为Ajax响应。

since your html wasn't defined as ajax response.