并非所有参数都在jquery ajax调用中发送

时间:2010-03-17 05:31:39

标签: c# asp.net javascript jquery ajax

我有一个奇怪的错误,我的jquery ajax请求不提交所有参数。

$.ajax({
    url: "/ajax/doAssignTask",
    type: 'GET',
    contentType: "application/json",
    data: { 
        "just_a_task": just_a_task,
        "fb_post_date": fb_post_date,
        "task_fb_postId": task_fb_postId,
        "sedia_task_guid": sedia_task_guid,
        "itemGuid": itemGuid,
        "itemType": itemType,
        "taskName": taskName,
        "assignedToUserGuid": assignedToUserGuid,
        "taskDescription": taskDescription
    },
    success: function(data, status) {
        //success code
    },
    error: function(xhr, desc, err) {
        //error code
    }
});

但是使用firebug(和调试)我可以看到只发布了这些变量:

assignedToUserGuid
itemGuid
itemType
just_a_task
taskDescription 
taskName

缺少fb_post_datetask_fb_postIdsedia_task_guid

我不知道是什么原因导致它只发布一些项而不发布其他项?有人知道吗?

将数据发送到返回jsonresult(因此为contentType)的asp.net控制器

感谢任何帮助。谢谢!

4 个答案:

答案 0 :(得分:2)

您应该如何帮助编码和调试将JSON数据移动到变量...即,您可以在发布之前轻松查看变量内部的内容

var myData = { 
    just_a_task: just_a_task,
    fb_post_date: fb_post_date,
    task_fb_postId: task_fb_postId,
    sedia_task_guid: sedia_task_guid,
    itemGuid: itemGuid,
    itemType: itemType,
    taskName: taskName,
    assignedToUserGuid: assignedToUserGuid,
    taskDescription: taskDescription
};
var jsonData = $.toJSON(myData);

$.ajax({
    url: "/ajax/doAssignTask",
    type: "GET",
    contentType: "application/json",
    dataType: "json",
    data: jsonData,
    success: function(data, status) {
        //success code
    },
    error: function(xhr, desc, err) {
        //error code
    }
});

虽然我没有时间运行代码,但可能是JSON中的语音标记。这应该是它的原生JavaScript

答案 1 :(得分:2)

您可以尝试以下内容:

  • 查看所有变量是否都有值
  • 尝试从变量名称中删除“_”

答案 2 :(得分:1)

检查数据值中的特殊字符(,{} []“')。您必须转义这些字符才能使JSON正常工作。

希望这有帮助。

答案 3 :(得分:0)

为了进行健全性检查,请尝试在您的选项中添加beforeSend,并确保正在发送这些值并从那里开始....

e.g。

.ajax({
    beforeSend: function (xhr) {
  // this==the options for this ajax request
  if(! fb_post_date || !task_fb_postId || ! sedia_task_guid){
    alert("BORKED!");
  }
},
....