Not all parameters are sent in jquery ajax call

I have a strange error when my jquery ajax request does not pass all parameters.

$.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
    }
});

But using firebug (and debugging), I see that only these variables are placed:

assignedToUserGuid
itemGuid
itemType
just_a_task
taskDescription 
taskName

Absent fb_post_date, task_fb_postIdandsedia_task_guid

I do not know what could make him publish only some subjects, and not others? Somebody knows?

Data is sent to the asp.net controller, which returns jsonresult (hence contentType)

Any help is appreciated. Thank!

+3
source share
4 answers

You can try some things, such as:

  • See if all variables have values
  • "_"
+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

+2

(, {} [] "'). JSON.

, .

+1

, beforeSend , ....

.

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

Source: https://habr.com/ru/post/1737284/


All Articles