简体   繁体   中英

Setting & saving a pointer in a certain class in parse.com with JavaScript

I am trying to create two pointers to store in a class called appointments. One pointer is for a teacher & other for the student. I have used a global variable for selectedTeacherId in another event to store the selected teachers user id as a string. below is my code. I get an error message 400 bad request. Why isn't my pointers & class saving?

 $('#final-submit').on('click', function() {

  var day= $('div#apt-detail-time li span#day').text();
  var time= $('div#apt-detail-time li span#time').text();
  var currentUser = Parse.User.current();
  var currentUserId = currentUser.id;
   var userPointer = {
  __type: 'Pointer',
  className: '_User',
  objectId: currentUserId
}
var teacherPointer = {
  __type: 'Pointer',
  className: '_User',
  objectId: selectedTeacherId
}


   var appointment = Parse.Object.extend("Appoinments");
   var newAppointment = new appointment();

   newAppointment.set('day', day);
   newAppointment.set('time', time); 
   newAppointment.set('type', 'pending');
   newAppointment.set('student', userPointer);
   newAppointment.set('teacher', teacherPointer);
   newAppointment.save();
   });   `

A few things may be causing your problems:

  1. Where is selectedTeacherId coming from? It's not defined in your function. Depending on how this is implemented, this may be the cause of your error.

  2. You spelled "Appointments" wrong in var appointment = Parse.Object.extend("Appoinments");

  3. I recommend that you always pass a success and error callback to any .save() calls. You can check on the Parse Javascript SDK documentations for idiomatic examples of this. By passing success and error callbacks, if you get a bad request or other error, you will be able to invoke an alert() or console.log() function to display the cause of the errors. Furthermore, there are bugs that might cause you to make an infinite number of requests to Parse. Because Parse charges money above a certain rate of requests, you may be charged unintentionally if you are not careful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM