简体   繁体   English

如何将/ post JSON数组从客户端传递到服务器?

[英]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? 我正在使用jQuery创建JSON数组,现在如何从客户端通过模式窗口将JSON数组传递或发布到服务器/后端?

When i click "Save Changes" on the modal window i want to pass/ post the 当我在模式窗口中单击“保存更改”时,我想通过/发布

var data = $(this).serializeObject() to the server. var data = $(this).serializeObject()到服务器。

How can I go about doing it from the client side using jQuery or javascript? 如何使用jQuery或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) 我的代码在jsfiddle的http://jsfiddle.net/dev1212/GP2Y6/30/中 (当用户单击提交但在我的本地计算机上工作时,模式窗口未显示在小提琴中)

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? 这是将JSON数组数据传递到服务器的正确方法吗?

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或自己处理httprequest。 ajax is really easy since you're using jQuery already. ajax非常简单,因为您已经在使用jQuery。

http://api.jquery.com/jQuery.ajax/ 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 . 您可以使用的格式,并通过JavaScript提交像这样 ,也可以通过类似的jQuery使用AJAX 这个

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. 使用"$.ajax"并通过"data"参数放置您的json数据。 You will get the data in the request object sending to the server. 您将在发送到服务器的请求对象中获得数据。

Cheers 干杯

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Flask 中将带有 Jquery 和 JSON 的 Javascript 数组从客户端传递到服务器端 - Pass Javascript array with Jquery and JSON from client-side to server side in Flask 如何将Ajax参数中的数组值从客户端传递到服务器端 - How To pass Array value in Ajax Parameter from Client side To Server side 如何将数组从Asp.net服务器端传递到客户端的Javascript函数 - How to pass array from Asp.net server side to Javascript function on client side 如何将一组数据从客户端传递到 axios 发布请求的 req.body - How to pass an array of data from the client side to req.body of an axios post request 有没有一种方法可以将包含日期的String数组从服务器端传递到客户端? - Is there a way to pass a String array containing dates from server side to client? 如何将 JSON 数据从服务器传递到客户端并在 Javascript 中使用数据? - How to pass JSON data from server to client side and use the data in Javascript? 将参数从服务器端传递到客户端 - To pass parameter from server side to client side 将参数从客户端传递到服务器端 - pass arguments from client side to server side 如何将json对象从jsp页面的jsp部分传递到javascript部分,即从服务器端到客户端? - How to pass a json object from the jsp part of a jsp page to the javascript part i.e from server side to client side? 使用 express 和 mongoose,如何使用 POST 路由将多个 ID 的数组从客户端发送到服务器端? - Using express and mongoose, how do I send an array of multiple IDs from the client-side to server-side using a POST route?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM