将数据发送到使用AJAX PHP

问题描述:

我有搜索发布这个问题之前,我的问题,但未能找到解决办法。 我需要发送一个JSON字符串到PHP文件,但未能如愿,可有人请帮我下面的问题:我是新来的PHP和jQuery和挣扎,需要您的合作,请

I have searched my problem before posting this question, but failed to find a solution. I need to send a json string to php file but unable to do so, can some one please help with my problems below: I'm new to php and jquery and is struggling, Need your cooperation please.

我有一个函数,捕获上的文本文件中的数据:

I have a function that captures data on the text file:

function updateVal() {
var node_list = document.getElementsByTagName('input');
var c = 0;
var fieldName = [];
var fieldText = []
var ID = [];
for (var i = 0; i < node_list.length; i++) {
    var node = node_list[i];
    if (node.getAttribute('type') == 'text') {
        fieldName[c] = node.name;
        fieldText[c] = node.value;
        ID[c] = node.id;
        c++;
    }
}
var postData = {
    fieldName: fieldName,
    fieldText: fieldText,
    ID: ID
};
 var dataString = JSON.stringify(postData);


console.log(JSON.stringify(postData));
$.ajax({
        type: "POST",
        dataType: "json",
        url: "update.php",
        data: {myData:postData}
        })

//return JSON.stringify(postData);
}

我的update.php是这样的:

My update.php is like this:

<?php
$json = $_POST['json'];
$result = json_decode($json);

echo $result;
echo $_POST['myData']);?>

在加载此:我收到以下错误:

On loading this: I'm getting the following error:

无法加载资源:与500(内部服务器错误)状态

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

另外,我不知道如果数据被发送到PHP与否。 请专家可以验证。

Moreover, I'm not sure if the data being sent to php or not. Can experts pls validate.

500(内部服务器错误)表示出现了错误的服务器端。因此,检查Apache的错误日志以了解更多详细信息

The 500 (internal server error) means something went wrong on the server's side. So check the apache error log for more details

您可以在这里找到Apache日志 /无功/日志/的Apache2 /

you may find apache log here /var/log/apache2/