weixin_33727510 2014-04-22 16:11 采纳率: 0%
浏览 33

使用jQuery错误更新JSON

I'm trying to update a JSON file with the value of a textarea using jquery push. I'm receiving the following error: " JavaScript runtime error: Unable to get property 'push' of undefined or null reference"

My jquery:

function submittedMsg(ctx) {
var id = $('.msg-input form').attr('id');
var newMsg = $('.msg-input textarea').val();

var url = "/ajax.aspx?vtl=ajax-conversation-json&cv=" + id;     

$.getJSON(url, function (messageString, message) {
    var message = [];

    message.push({
        msgcontent: newMsg,
        sendname: sendRname,
        mbrhref: mbrUrl,
        datetime: ""
    });
});
}

My JSON:

{
"messageString" :
[

{ "subject": "hello",
  "msgstring": "5",
  "unread": "1",
  "datetime": "Oct  1 2013  9:59PM",
  "orderid": "17",
  "recipient": [
      {
       "mbrname": "Jane Doe",
       "mbrhref": "/profile.aspx?mem=1227"
      },
      {
       "mbrname": "John Smith",
       "mbrhref": "/profile.aspx?mem=1337"
      }
],
  "message": [
      {
      "datetime":"2013-10-01T21:59:33.063",
      "sendname":"Jane Doe",
      "mbrhref":"/profile.aspx?mem=1227",
      "msgcontent": "<p>Hi. I would like to talk with you about Dwarf Beryl Beauty</p>"
      },
      {
      "datetime":"2013-11-26T16:29:17.037",
      "sendname":"John Smith",
      "mbrhref":"/profile.aspx?mem=1337",
      "msgcontent": "Tough luck."
       }
  ]
}
]
}

I don't necessarily need to use push to update the JSON file if there is a better way, I'm open to suggestions. I've verified my URL path is correct. Am I just missing something obvious? I'm new to JSON and only have passable jquery skills. Help!

Thanks in advance for any direction.

  • 写回答

2条回答 默认 最新

  • weixin_33712881 2014-04-22 16:12
    关注

    Try to use:

    data.message.push
    

    instead of:

    data.messageString.message.push
    
    评论

报告相同问题?