データベース テーブルに対してクエリを実行するクリック イベントがあり、クエリが返すオブジェクトの長さに応じて異なるアラートをトリガーするはずです。このクエリはテーブルをチェックして、ユーザーが特定のオブジェクト ID に関連するユーザー情報を既に保存しているかどうかを確認します。id はイベントを表します。ユーザーが同じイベントの情報を 2 回保存できないようにしたい。そのため、リンクが初めてクリックされると、クエリはテーブルをチェックして、そのイベント ID に関連する情報が既に保存されているかどうかを確認します。保存されていない場合は、情報をイベント ID と共に保存します。しかし、そのリンクが 2 回目にクリックされたときに、情報を既に送信したことをユーザーに通知するメッセージを表示したいと考えています。どういうわけかテストすると、条件が2回目は機能しません。
$("#mainDiv").on('click', '.interested', function (event) {
//get id attribute of the clicked "interested" link. It stores the id of the activity.
var activityID = $(event.target).attr('id');
/*instantiate object that will hold info about interested user. The constructor function and variables are declared in a different part of my code*/
var intrstd = new interested(hood, gender, dateOfBirth, zip, uID);
/*check the "Interested" table on Parse to see if the user already has info stored for this activity */
var check = Parse.Object.extend("Interested");
var interest = new Parse.Query(check);
//these are query constrains that pick out the colum values I want.
interest.equalTo("parent", activityID);
interest.equalTo("InterestedPPL", intrstd.uID);
//interest.find() executes the query and "results" contains the return object
interest.find({
success: function (results) {
/*if the user info is already saved for the specific id, show the alert, if not store the object containing their user info */
if (results.length !== 0) {
alert("you have already requested an invite to that activity");
} else {
var show = Parse.Object.extend("Interested");
var int = new show();
int.set("parent", activityID);
int.set("InterestedPPL", intrstd);
int.save();
alert("you will be notified if you have been invited to this activity");
} //closes else
},
error: function (object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and description.
console.log("Error: " + error.code + " " + error.message);
}
}); //closes find
}); //closes on