且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

发送POST请求时无效的JSON原语

更新时间:2023-01-17 08:12:47

您的问题是因为您没有发送有效的JSON.您需要将密钥用双引号引起来.另外,subscriptionJson是代码中的文字字符串.您需要将其作为字符串变量.

Your issue is because you're not sending valid JSON. You need to wrap the keys in double quotes. Also, subscriptionJson is a literal string in your code. You need it to be a string variable.

data: '{"subscriptions": ' + subscriptionJson + '}',

或者更好的是,只需为jQuery提供一个普通对象,然后让它为您编码值即可:

Or, even better, just provide a plain object to jQuery and let it encode the values for you:

data: { subscriptions: subscriptionJson },