问题
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