Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Objects within Objects #24

Open
Maelstromeous opened this issue Dec 30, 2015 · 4 comments
Open

Objects within Objects #24

Maelstromeous opened this issue Dec 30, 2015 · 4 comments
Assignees
Labels
Milestone

Comments

@Maelstromeous
Copy link

Maelstromeous commented Dec 30, 2015

Hi there,

I'm attempting to send an object like the one below:

var data = {
    "wheres": {
        ResultServer: 1
    }
};

Then using:

aja()
    .method('post')
    .url('some_url')
    .data(data)
    .on('200', function(response) {
        return response
})

It appears though that what's being sent is [object Object] in the second indentation, am I doing something wrong?

I'm outputting the POST request on the receiving end, getting this:

{"wheres":"[object Object]"}

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/29481720-objects-within-objects?utm_campaign=plugin&utm_content=tracker%2F6332594&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F6332594&utm_medium=issues&utm_source=github).
@Maelstromeous
Copy link
Author

I've just had a good tinker, I was able to get round it by using JSON.stringify to populate the object in the second indentation, on ResultServer: 1, then things worked as normal, so the request then became:

var data = {
    "wheres": {
        "{"ResultServer":1}"
    }
};

Is this a case of I'm doing something that wasn't intended to be supported by aja?

@krampstudio
Copy link
Owner

Could you try :

aja()
    .method('post')
    .type('json')
    .url('some_url')
    .data(data)
    .on('200', function(response) {
        return response
     });

because data() set the value either in body or encoded regarding the context. If you don't want to specify the type you can enforce the encoding of the data in the body using the body() method instead.

@Maelstromeous
Copy link
Author

Ahh I see now, that indeed worked, thanks. I must have glazed over that part of the documentation :P

@Maelstromeous
Copy link
Author

Actually sorry, upon further investigation this wasn't fixed, still getting the output of [object Object].

@Maelstromeous Maelstromeous reopened this Jan 5, 2016
@krampstudio krampstudio added this to the 1.0.0 milestone Feb 28, 2016
@krampstudio krampstudio self-assigned this Feb 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants