2017-07-31 55 views
1

我有一个工作的jQuery程序,谈论一个服务器上的PHP程序,我正在从PHP到前端移动JSON数据是没有问题的。传递JSON与jQuery的

现在我需要JSON数据发送到我的后端PHP服务器

当我使用这个语法

'$.post("../wrk/filterquest.php",{ 
    "yesTransactionId" : "yesTransactionId", 
    "oproductOfferId" : "productOfferId" 
    }, 
    function ...' 

我的PHP接收它。我检查,列出测试文件PHP构建

[email protected] [~/public_html/wrk]# cat test 
filterquestPOST=array (
yesTransactionId => yesTransactionId, 
oproductOfferId => productOfferId, 
) 
GET=array (
) 

然而,当我宣布一个字符串,并同一JSON手动加载到其中

'poststr = " {\"yesTransactionId\" : \"yesTransactionId\", \"oproductOfferId\" : \"productOfferId\"}";' 

我并尝试发送它

$.post("../wrk/filterquest.php",poststr, 
function... 

我的php没有得到它

[email protected] [~/public_html/wrk]# cat test 
filterquestPOST=array (
) 
GET=array (
) 

如果你关心写我用它来跟踪貌似

'<?php 

try 
{ 

// Debug 
$debu = "> test"; 
exec($debu); 
$lang_str = var_export($_POST,true); 
$debu = "echo 'filterquestPOST=". $lang_str ."' >test"; 
exec($debu); 
$lang_str = var_export($_GET,true); 
$debu = "echo 'GET=". $lang_str ."' >>test"; 
exec($debu); 
//Open database connection ....' 

测试文件的PHP那么什么是语法我需要把JSON字符串中的,并得到该字符串变量到后端服务器? (注意:我可以建立一个javascript数组,并使用JSON.stringify加载多串,但我甚至无法得到这个简单的字符串移动。

感谢

+1

JSON是不是字符串,但poststr是一个字符串。 – inarilo

回答

0

我试图通过基本数组存储在c_char_val。

我曾以为我已经将它移到一个字符串,并没有与此命令

var poststr = JSON.stringify(c_char_val); 

但是我发现一个线程说,我不需要那样做。

相反,我用这个语法,WORKS

$.post("../wrk/filterquest.php",{myData:c_char_val}, 
function(... 

这给了我这样的结果,当我检查我的后端服务器传递

[email protected] [~/public_html/wrk]# cat test 
filterquestPOST=array (
myData => 
    array (
    Picked => 
    array (
    0 => 
     array (
     char_id => char11, 
     charval_id => 12, 
    ), 
    ), 
), 
) 
GET=array (
)