简体   繁体   中英

Parse Query error - 400 : Bad request upon data insertion

I am trying to implement data insertion on the parse database. However I keep getting this 400 (Bad Request) error. Not able to figure out what might be the problem. Below is the code :

var newsNo = localStorage.getItem("NewsNo");
newsFeedQuery.equalTo("NewsNo",Number(newsNo));
newsFeedQuery.first({
 success : function(results)
 {
     console.log("RESUTS ID : "+results.id);
     nws = results.id; 
     console.log("OBJECT ID : "+nws);

     //Updating the likes table
     var Likes = Parse.Object.extend("Likes");
     var likes = new Likes();

     console.log("Setting in like table News ID : "+nws);
     console.log("Setting in User Id : "+Parse.User.current().id);

     likes.set("NewsLikedId", nws);
     likes.set("UserId", Parse.User.current());
     likes.save({
             success : function()
             {
                 console.log("Successfully updated Like table");
             }, error : function(error)
             {
                 console.log("Error in like table : "+error.message);
             }
         });
     //Updating the likes table

 }, error : function(error)
 {
     console.log("Error: "+error);
 }
});

This line is getting printed : console.log("Error in like table : "+error.message); .

Console Result :

POST https://api.parse.com/1/classes/Likes 400 (Bad Request)
Error in like table : undefined

Please note : The columns "UserId" and "NewsLikedId" both are of pointer type which are pointing to User and my custom made 'NewsFeed' table. So I need to set pointer data only. On these lines in my code

console.log("Setting in like table News ID : "+nws);
console.log("Setting in User Id : "+Parse.User.current().id);

I am getting the desired output. Only need to set it to the Likes table.

To answer more accurate I would need to have a look at your "Likes" table. But I assume the error is that there is some kind of type missmatch here:

likes.set("UserId", Parse.User.current());

it looks like you try to set up a pointer to the current user object. The name "UserId" suggests, that you actually want to save an ID and not a pointer. Replace it with:

likes.set("UserId", Parse.User.current().id);

and try again.

Hope this helped.

EDIT:

if NewsLikedID is also of type pointer then you should consider writing the "results" object into nws instead of results.id:

nws = results.id; //wrong
nws = results; //correct

please try this and report back.

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