Setting processData to false in jQuery breaks my AJAX request

后端 未结 3 478
名媛妹妹
名媛妹妹 2020-11-28 12:15

I\'ve googled for a while now and can only find what processData: false does. I can\'t find anyone who has experienced this same issue.

I\'m passing JSO

3条回答
  •  情深已故
    2020-11-28 12:34

    Actually, processData by default assumes that data passed is an object and sends it as application/x-www-form-urlencoded.

    Summing up everything said above by @lonesomeday and @vsm to send raw JSON (what is different from the form data) you need to:

    $.ajax({
        url: 'http://here-i.am/send-me/an/angel', // Determining far end
        data: JSON.stringify({foo: "bar"}), // Obtaining proper JSON string from data object
        processData: false, // Preventing default data parse behavior
        contentType: "application/json" // Setting proper `ContentType` for our data
        ...
    });
    

提交回复
热议问题