jquery-form/form

Post json within request body

Open

#545 ouverte le 4 mars 2018

Voir sur GitHub
 (4 commentaires) (4 réactions) (0 assignés)JavaScript (2 199 forks)batch import
featurehelp wantedtest needed

Métriques du dépôt

Stars
 (5 209 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

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.

Guide contributeur