Skip to content

Post json within request body #545

Open
@zhangciwu

Description

@zhangciwu

This is a feature request, and I think it's raised in #531 but misunderstanded

Description:

Now only form data format is supported in this plugin, I'd like to post json data in post body (like this: https://stackoverflow.com/questions/5570747/jquery-posting-json)

In jquery it can be done with code below:

$.ajax(url, {
    data : JSON.stringify(myJSObject),
    contentType : 'application/json',
    type : 'POST',
    ...

Expected Behavior:

With option:

contentType : 'application/json',

Request body like this :

{"name":"apple","count":"1"}

Actual behavior:

Unsupported, now only encoded form data can be in post body
Request body like this:

name=apple&count=1

Why

It's quite common in now days for communicating with server in protocol of json instead of form data, so this feature is needed.

Activity

zhangciwu

zhangciwu commented on Mar 4, 2018

@zhangciwu
Author

Workaound

Use https://github.com/marioizquierdo/jquery.serializeJSON to generate json and post with jquery, like:

var myData=$('form').serializeJSON();
$.ajax(url, {
    data : JSON.stringify(myData),
    contentType : 'application/json',
    type : 'POST'
});
kevindb

kevindb commented on Jun 29, 2018

@kevindb
Contributor

I see. That makes a lot of sense.

I have added the "help wanted" label to this issue. Would you please submit a pull request to add this feature? I am very open and responsive to pull requests.

errajswami

errajswami commented on Sep 14, 2018

@errajswami

Is it still open?

zhangciwu

zhangciwu commented on Sep 19, 2018

@zhangciwu
Author

Raised PR #557

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zhangciwu@kevindb@errajswami

        Issue actions

          Post json within request body · Issue #545 · jquery-form/form