NicolasCARPi / jquery_jeditable

jQuery edit in place plugin. Extendable via plugin architecture. Plugins for plugin. Really.
https://jeditable.elabftw.net
MIT License
1.74k stars 458 forks source link

POST Json Data via Ajax #168

Closed NLI-KelbyHunt closed 6 years ago

NLI-KelbyHunt commented 6 years ago

Description

When I add ajaxoptions and content type of application/json, I see the values sent in the body of the request but they are not in Json format. ASP controllers are picky and I cannot get this to bind to parameters value=testvalue&id=1 Is there a way to JSON.stringify the POST data? I just want the id/value to be converted to JSON string before sending it while still picking up those values automatically from the HTML element.

Unrelated question, can you use Glyph Icons/Font Icons as the button text with bootstrap classes?

how to reproduce

$("table > tbody td > div.cronExpression").editable("@Url.Action(nameof(AdministrationController.EditCronExpression))", {
            ajaxoptions: {
                contentType: "application/json"
            },
            cancel: "Cancel",
            cancelcssclass: "btn btn-secondary",
            submit: "Save",
            submitcssclass: "btn btn-success",
            callback: function() {
                window.location.reload();
            }
        });

I have attempted a couple things:

submitdata: function (revert, settings, submitdata) {
                return JSON.stringify(submitdata);
            }
ajaxoptions: {
                contentType: "application/json",
                data: function(params) {
                    return JSON.stringify(params);
                }
            },

expected result

{"value":"testvalue", "id":1}

actual result

value=testvalue&id=1

Environment

Browser: Chrome OS: Windows

NicolasCARPi commented 6 years ago

Hello,

Is there a way to JSON.stringify the POST data?

Why don't you put the target as a JS function? This way you do whatever you want to the data before sending it! ;)

can you use Glyph Icons/Font Icons as the button text with bootstrap classes?

Didn't try it.

NLI-KelbyHunt commented 6 years ago

Why don't you put the target as a JS function? This way you do whatever you want to the data before sending it! ;)

Don't know why I didn't think of that, I'll write a PreProcess function. Thanks @NicolasCARPi