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

Bad content parsing when using nested JSON objects in post() #68

Open
jparreira opened this issue Nov 11, 2013 · 3 comments
Open

Bad content parsing when using nested JSON objects in post() #68

jparreira opened this issue Nov 11, 2013 · 3 comments
Assignees

Comments

@jparreira
Copy link

If one runs:

<%
var url = 'http://jaggeryjs.org/apidocs/resources/data.jag';
var result = post(url,
{"key": {
"primary":"foo",
"secondary":"bar"}
},
{
"User-Agent" : "Jaggery-XHR",
"Country" : "LK"
},
'json');
print(result.data);
%>

at http://jaggeryjs.org/apidocs/post.jag "try it" feature, gets as result:

{"method" : "POST", "url" : "http://jaggeryjs.org/apidocs/resources/data.jag", "content" : "key=%5Bobject%20Object%5D", "headers" : {"host" : "jaggeryjs.org", "user-agent" : "Jaggery-XHR", "country" : "LK", "x-forwarded-for" : "204.13.82.231", "x-forwarded-host" : "jaggeryjs.org", "x-forwarded-server" : "jaggeryjs.org", "connection" : "Keep-Alive", "content-length" : "25"}}

The content posted is key=%5Bobject%20Object%5D instead of
{"key": { "primary":"foo", "secondary":"bar"} }

@ghost ghost assigned manuranga Nov 12, 2013
@manuranga
Copy link
Contributor

I'll am investigating this issue.
but anyway, your requirement doesn't seems to be addressed with this code snippet regardless of the issue.
to send a json string as the POST's content, set the data as a string.

<%
var url = 'http://jaggeryjs.org/apidocs/resources/data.jag';
var data = stringify({"key": {
    "primary": "foo",
    "secondary": "bar"}
});
var result = post(url, data,
        {
            "User-Agent": "Jaggery-XHR",
            "Country": "LK"
        },
        'json');
print(result.data);
%>

@jparreira
Copy link
Author

If the REST service does a JSON parse it'll work. But since the post() data parameter can be a string or an object I guess Jaggery should handle the Object option better with support for nested Objects.

@manuranga
Copy link
Contributor

Yes, ideally following Jaggery code

<%
var url = 'http://jaggeryjs.org/apidocs/resources/data.jag';
var data = {"key": {
    "primary": "foo",
    "secondary": "bar"}
};
var result = post(url, data,
        {
            "User-Agent": "Jaggery-XHR",
            "Country": "LK"
        },
        'json');
print(result.data);
%>

should send a POST with following content

key%5Bprimary%5D=foo&key%5Bsecondary%5D=bar

I will provide a fix for this. FIY, post() method in Jaggery is modeled after jQuery.post

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants