0
var data = {
    'ids': $("input[name='ids\\[\\]']").map(function(){return $(this).val();}),
    'price': $("input[name='price\\[\\]']").map(function(){return $(this).val();})
};

alert(data);


$.post("api/update_prices.php", {'data[]': data}, function (responseText) {
    alert(responseText);
});

or...

$.post("api/update_prices.php", data, function (responseText) {
    alert(responseText);
});

The alert data is outputting a Object (object). I was looking a Stackoverflow and it's still not working. alert(responseText) is never called.

1
  • Your second snippet should work. Isolate the code and try to find the problem. If you are on safari/chrome/firefox use console.log() to inspect objects with help of the javascript console. Commented Aug 11, 2013 at 10:31

3 Answers 3

1

Did you try specifying the content type as "application/json" in the jQuery Ajax API and then calling

JSON.stringify(data);

also, open the web developer console in Google Chrome browser and navigate to the Network tab to see what is happening during the Ajax call. i.e. what data is sent and what data is received in the Ajax Call.

Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried serialize? It sums up all the form data. It seems to be what you're trying to do with the data object.

$.post("api/update_prices.php", $(':input').serialize(), function (responseText) {
    alert(responseText);
});

http://api.jquery.com/serialize/

Comments

0

Your $.post function should be like this:

$.post("api/update_prices.php", {'data[]': JSON.stringify(data)}, function (responseText)  {
    alert(responseText);
});

Pay attention to JSON.stringify.

Comments

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.