admin管理员组文章数量:1323723
var mydata = {
"one": {
"brand": "acer",
"cost": "212132"
}
}
$.ajax({
url: 'http://localhost',
type: 'post',
dataType: 'json',
data: JSON.stringify(mydata)
});
Above code is adding a colon to the data when i view the form send data in chrome dev tools. Is there anything wrong with the request?
var mydata = {
"one": {
"brand": "acer",
"cost": "212132"
}
}
$.ajax({
url: 'http://localhost',
type: 'post',
dataType: 'json',
data: JSON.stringify(mydata)
});
Above code is adding a colon to the data when i view the form send data in chrome dev tools. Is there anything wrong with the request?
Share Improve this question asked Nov 11, 2013 at 5:42 Rafa TostRafa Tost 3995 silver badges13 bronze badges 7-
you didn't close the quote in
url: 'http://localhost,
. It should beurl: 'http://localhost',
– RRikesh Commented Nov 11, 2013 at 5:45 - you missed single quote after url – Dart Commented Nov 11, 2013 at 5:45
-
2
if you want to send the data as parameters then
data: mydata
– Arun P Johny Commented Nov 11, 2013 at 5:49 -
2
Do you mean that you see a trailing
:
inNetwork > Headers > Form Data
({"one":{"brand":"acer","cost":"212132"}}:
) if so thats what I also see. It is because you send it as plain data - passing it withdata: JSON.stringify(mydata)
- and not withdata: mydata
, but it does not mean that the colon is really send to the server. – t.niese Commented Nov 11, 2013 at 5:54 - 2 could be, cause no identifier is send(i mean variable name, like login="some login"); you can try {data: JSON.stringify(mydata)} – Dart Commented Nov 11, 2013 at 6:01
2 Answers
Reset to default 8You are viewing application/x-www-form-urlencoded parsed data. So Chrome is trying to establish key value pairs. Click "view source" near the "Form Data" heading in the network tab view. You will see your JSON without the colon.
Was the same for me. I did not see the colon when viewing source. BUT it did not work.
My solution was to add the missing contentType
$.ajax({
url: `url`,
contentType: "application/json",
type: "POST",
data: JSON.stringify(data)
});
本文标签: javascriptajax json adding trailing colonStack Overflow
版权声明:本文标题:javascript - ajax json adding trailing colon - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742124296a2421866.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论