如何在javascript中的对象键中正确包含破折号? [英] How do I correctly include a dash in an object key in javascript?
本文介绍了如何在javascript中的对象键中正确包含破折号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试使用这样的代码时:
When I try to use a code like this:
jQuery.post("http://mywebsite.com/", {
array-key: "hello"
});
我收到此错误:
未捕获的SyntaxError:意外令牌-
Uncaught SyntaxError: Unexpected token -
我尝试将密钥用引号引起来,但是没有任何反应.我想知道这是由于我在另一个网站上犯了一些其他错误还是因为这不是如何在对象的键中包含破折号.如果不是,我想知道如何去做.预先感谢.
I tried surrounding the key in quotation marks, but nothing happened. I'd like to know if it's because of some other mistake I am making at the other website or because that's not how to include a dash in an object's key. And if it's not I'd like to know how to do it. Thanks in advance.
推荐答案
jQuery.post("http://mywebsite.com/", {"array-key": "hello"});
应该是正确的.如果这不起作用,则问题与您的请求无关.
should be correct. If this doesn't work, the issue is not with your request.
这篇关于如何在javascript中的对象键中正确包含破折号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文