ajax怎么发送数据给php,使用AJAX将数据发送到PHP (Sending data to PHP using AJAX)

2015-10-21 04:52:45

0

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);

}

My update.php is like this:

$json = $_POST['json'];

$result = json_decode($json);

echo $result;

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

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

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

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

Can experts pls validate.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值