简体   繁体   中英

How to pass /post JSON array to the server from the client side?

I am using jQuery to create a JSON array, and now from the client side how do I pass or post the JSON array to the server/backend from the modal window?

When i click "Save Changes" on the modal window i want to pass/ post the

var data = $(this).serializeObject() to the server.

How can I go about doing it from the client side using jQuery or javascript?

My code is here in jsfiddle http://jsfiddle.net/dev1212/GP2Y6/30/ ( modal window is not showing up in the fiddle when the user click submit but work on my local machine)

Is the right way to go about posting it to the server?

Would this be the right way to pass the JSON array data to the server?

This is my updated version:

$.ajax({
    type: 'POST',

    url: 'http://re-directb-acktohomepage.com/',
contentType:'application/json'
    data: data,
    success: 
        alert('success');

});

Look into ajax or handling the httprequest yourself. ajax is really easy since you're using jQuery already.

http://api.jquery.com/jQuery.ajax/

You can either use a form and submit it through javascript like this or you can use AJAX through jQuery like this .

One will redirect your page and one will post the data while keeping your browser on the same page. This question has been answered many times on this site so you could also look around for a more in depth answer.

Use "$.ajax" and put your json data through the "data" parameter. You will get the data in the request object sending to the server.

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM