weixin_33670786 2015-05-12 19:49 采纳率: 0%
浏览 53

jQuery Ajax POST JSON问题

I'm trying to pass a JavaScript array into a PHP script to then be put into a database but I'm having issues. I have used JSON.stringify on the array before sending. The request seems to work in that when stepping through the code debugging the php page is called but no data is passed into the POST global. I'm sure its something amateurish that I've missed but I'm struggling. This is the code:-

$.ajax({
    type: "POST",
    datatype: "json",
    url: "processdraw.php",
    data: {
        json: pDrawnTeams
    },
    contentType: "application/json; charset=utf-8",
    success: alert('worked')
})
  • 写回答

1条回答 默认 最新

  • weixin_33694620 2015-05-13 00:39
    关注

    If you are not getting any error in your javascript, make sure that you are getting that parameter like this in your php target file:

    $myJSON = $_POST['json']; // ['parameter name']
    

    after that you will need to decode that json

    $myData = json_decode($myJSON, true) // true is for retrieving as an array
    
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)