[英]Serializing a JSON object to send via AJAX
I'm trying to send some data in a JSobject via AJAX using jQuery. 我正在尝试使用jQuery通过AJAX在JSobject中发送一些数据。
Here's the json object. 这是json对象。
var cookieData = {
'land' : document.URL,
'ref' : document.referrer
};
The object is them stored in a cookie... via JSON.stringify(cookieData);
对象是通过JSON.stringify(cookieData);
将它们存储在cookie中的JSON.stringify(cookieData);
Before the form is sent and AJAX post is made, I need to get the object's properties: 在发送表单和进行AJAX发布之前,我需要获取对象的属性:
var cookieData = cookie.get(website); //return the cookieData in stringified form.
var submitData = 'tracking=' +cookieData + jQuery("#quoteForm").serialize();
However, on the receiving application's end, the data is unusable, is there any way that I can serialize it for use in an AJAX post? 但是,在接收应用程序的一端,数据不可用,我有什么方法可以序列化它以用于AJAX帖子?
The receiving end is a PHP application, processed with: 接收端是一个PHP应用程序,使用以下代码处理:
$trackingData = json_decode(htmlspecialchars_decode($_POST['tracking']),true);
May be that the problem is a missing &, try this 可能是问题遗失了&,请尝试此操作
var submitData = 'tracking=' + cookieData + '&' + jQuery("#quoteForm").serialize();
By the way, which error return php or the json_decode/whatever you use to decode the json? 顺便说一句,哪个错误返回php或json_decode /无论您使用什么解码json?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.