How do I correctly include a dash in an object key in javascript?

414
November 26, 2016, at 6:29 PM

When I try to use a code like this:

jQuery.post("http://mywebsite.com/", {
    array-key: "hello"
});

I get this error:

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.

Answer 1
jQuery.post("http://mywebsite.com/", {"array-key": "hello"});

should be correct. If this doesn't work, the issue is not with your request.

Rent Charter Buses Company
READ ALSO
How to de-select a jsTree Checkbox by node ID

How to de-select a jsTree Checkbox by node ID

How can we able to de-select a node check box by its node ID in jsTree

750
Get a user selected file as a base64 encoded string for a live preview of the image as well as for linking it in the final result

Get a user selected file as a base64 encoded string for a live preview of the image as well as for linking it in the final result

I am using a PHP file uploader to enable a user to upload imagesHowever, due to some issues it is not working at all - the images are not uploading and the PHP script is not even creating an (empty in such cases) entries in a file

239
SignalR in ASP.NET WebForms

SignalR in ASP.NET WebForms

In one of my projects I need to use SignalR librarySo I decided to create one simple app to check how it works

657