[英]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.