[英]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. 但是,我不断收到此
400 (Bad Request)
错误。 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.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. 请注意:
"UserId"
和"NewsLikedId"
列均为指针类型,它们指向User和我的定制'NewsFeed'
表。 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.
只需要将其设置为Likes表即可。
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.
名称“ UserId”建议您实际上要保存一个ID,而不是一个指针。 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: 如果NewsLikedID也是指针类型,则应考虑将“结果”对象写入nws而不是results.id:
nws = results.id; //wrong
nws = results; //correct
please try this and report back. 请尝试此操作并报告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.