0

First of I admit that I am really bad at js and just got started. I have this snippet in the repository:

function sendReport() {
    $.post($('#reportForm').attr('action') + '/post', $("#reportForm").serialize()).done(function() {
      reportManager.run();
    });
}

And I want to add data to it. I want the webservice that is receiving the post to receive an additional key/value-pair. I tried something like

var data = $('#reportForm').serializeArray();
data.push({name: 'stuff', value: 'blaha'});

$.post(data, $("#reportForm").serialize()).done(function() {
    reportManager.run();
});

Didn't work at all and I would really appreciate any help with this.

EDIT:

Tried doing the suggestion below, didn't work. Tried this just to verify that the new parameter didn't ruin anything:

//data to post
var data = $('#reportForm').serializeArray();

//url to post
var url = $('#reportForm').attr('action') + '/post';

//options required for jQuery.post
var options = { "data":data, "url": url };

$.post(options).done(function() {
    reportManager.run();
});

That doesn't work. I'm getting an error like this on the server:

noHandlerFound No mapping found for HTTP request with URI [/[object Object]]

I am considering that something else in the code might be using some implicit behaviour, but I find it strange that trying the code above(without even adding new data) can break the current working behaviour.

7
  • the first parameter of jquery post must be an uri? Commented Aug 9, 2017 at 18:00
  • Buddy, always start with api documentation, not stackoverflow: api.jquery.com/jquery.post Commented Aug 9, 2017 at 18:02
  • reportManager.run() provides the uri. Before my modifications the post is working fine. Commented Aug 9, 2017 at 18:02
  • @why_vincent: You are not providing valid parameters to a method call Commented Aug 9, 2017 at 18:03
  • your first parameter seems to be an array, not string Commented Aug 9, 2017 at 18:06

1 Answer 1

2

You are not providing uri parameter for post method, you should use something similar to:

//data to post
var data = $('#reportForm').serializeArray();
data.push({name: 'stuff', value: 'blaha'});

//url to post
var url = $('#reportForm').attr('action') + '/post';

//options required for jQuery.post
var options = { "data":data, "url": url };

$.post(options).done(function() {
    reportManager.run();
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for the suggestion. Didn't work however. I have edited my post. Since performing the operation above without the push breaks behaviour then it must do more than just add a piece of data. Could there be anything else that has to be done? This might be a strange exceptional case. As I said I am new to js so this is a bit of a mystery to me and your help is greatly appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.