根据以下评论更新JS代码。现在警告框返回输入框中输入的内容,但是我没有看到它查询解析是否存在该用户。
var friendName;
$('#friendsearch').on('keyup', function(e) {
friendName = $(e.target).val();
var query = new Parse.Query(Parse.User);
query.equalTo("username", friendName); // find users that match
query.find({
success: function(friend) {
alert(friendName);
},
error: function (error) {
//Show if no user was found to match
alert("Error: " + error.code + " " + error.message);
}
});
});
使用parse.com和JavaScript SDK,此代码应捕获输入框中的输入,然后针对解析数据库中的现有用户进行查询。
它运行没有问题,但警告框总是返回“未定义”我假设“friendName”变量设置正确有问题?
即使使用调试器,我也很难理解为什么会这样。
任何帮助,我都很感激。
url http://kudosoo.com/findfriends.html?
<form class="Find Friend">
<div class="error" style="display:none"></div>
<input type="text" id="friendsearch" placeholder="Find Friend" class="input-field" required/>
<button type="submit" class="btn btn-login">Find</button>
</form>
<!-- Initialize the Parse object-->
<script type="text/javascript">
Parse.initialize("xxx", "xxx");
var friendName;
$('#friendsearch').on('keyup', function(e) {
friendName = $(e.target).val();
});
var query = new Parse.Query(Parse.User);
query.equalTo("username", friendName); // find users that match
query.find({
success: function(friend) {
alert(friendName);
},
error: function (error) {
//Show if no user was found to match
alert("Error: " + error.code + " " + error.message);
}
});
</script>
答案 0 :(得分:0)
您必须在输入keyup事件中调用ajax请求,以搜索任何特定值:
var friendName;
$('#friendsearch').on('keyup', function (e) {
friendName = $(e.target).val();
var query = new Parse.Query(Parse.User);
query.equalTo("username", friendName); // find users that match
query.find({
success: function (friend) {
alert(friendName);
},
error: function (error) {
//Show if no user was found to match
alert("Error: " + error.code + " " + error.message);
}
});
});