ajax call on keyup()

纵然是瞬间 提交于 2019-12-24 14:30:30

问题


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);
        }
    });
});

And this is control.php:

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

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

Thanks for any help.


回答1:


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

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

to

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

since your html wasn't defined as ajax response.



来源:https://stackoverflow.com/questions/10968419/ajax-call-on-keyup

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!