gpt4 book ai didi

javascript - 错误: The key is invalid JQuery syntax because it is missing a closing bracket

转载 作者:行者123 更新时间:2023-11-28 11:04:09 38 4
gpt4 key购买 nike

当我尝试向我正在使用的政府私有(private) API 测试服务器请求响应时,我在 Chrome 控制台中收到此错误。它说语法错误,但我根本没有看到缺少的括号。Edge 控制台给出了额外的错误文本

BAD REQUEST - The request could not be processed by the server due to invalid syntax.

否则 Edge 会出现与 chrome 中相同的错误:

    {"Message":"The request is invalid.",
"ModelState":{"message":[
"The key is invalid JQuery syntax because it is missing a closing bracket\r\nParameter name: key"]}},
"status":400,
"statusText":"Bad Request"}

我只是编写一个测试请求,尝试将 xml 表单发布到测试服务器上的预期消息收件箱。 (政府测试服务器不是我的)

我尝试了很多变体,并查看了 api 文档以获取可能的解释。这是代码:

<script>
$(document).ready(function() {
var postData = "";
var xmltext = "";
$.get('TiltakUtenAnsvarsrett.xml', function(tiltakutenansvarsrettXML) {
xmltext = tiltakutenansvarsrettXML;
//xmltest = xmltext.replace(/"/g, '\\"');
console.log("Dette er xmltext variablen" + xmltext);

//console.log("Dette er xmltext variablen stringified" + JSON.stringify(xmltext));
}, 'text');
$("#formtext").click(function() {

this.postData = {
"Type": "FormTask",
"ServiceCode": "4373",
"ServiceEdition": "1",
"_embedded": {
"forms": [{
"Type": "MainForm",
"DataFormatId": "5508",
"DataFormatVersion": "41083",
"FormData": xmltext
}

],
"attachments": [{
"Filename": "String example",
"Attachmenttype": "String example 2",
"Data": "Base64 encoded"
}]
}
};
$.ajax({
url: "https://xxx.xxxx.xx/api/my/messages",
headers: {
"Accept": "application/hal+json",
"ApiKey": "xxxxxxx",
},
xhrFields: {
withCredentials: true
},
type: "POST",
data: JSON.stringify(this.postData),
success: function(data, status, jqHxr) {
console.log("====== Returned messages ======");
console.log(JSON.stringify(data));
}.bind(this),
error: function(jqHxr, textStatus, errorThrown) {
console.log("Kaster feil status");
console.log("jqHxr er: " + JSON.stringify(jqHxr) + "\n");
console.log("Status er: " + textStatus + "\n");
console.log("Erroren er: " + errorThrown + "\n");
console.log("postData er: " + JSON.stringify(this.postData) + "\n");
console.log("Responsetext er: " + jqHxr.responseText);
console.log();
}.bind(this)
});
});
});
</script>

Google 搜索仅给出了此错误消息的少数情况,不足以继续下去。

最佳答案

如果服务需要 JSON,请添加 contentType json

type: "POST",
contentType:"application/json",
data: JSON.stringify(this.postData),
success: function(data, status, jqHxr) {

关于javascript - 错误: The key is invalid JQuery syntax because it is missing a closing bracket,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44521928/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com