ASP.NET: jQuery AJAX 'data' param problem

前端 未结 3 1289
温柔的废话
温柔的废话 2020-12-16 13:49

I\'ve been having problems with this code I had spent the last 3 hours digging around and trying to find an answer. As I wasn\'t successful, I will just post the code and as

3条回答
  •  北海茫月
    2020-12-16 14:24

    Try passing the data as a string, not an object, ie:

    $.ajax( {
        ...
        data : '{ a: 2, b: 3 }',
        ...
    } );
    

    The reasoning for this is that if you specify an object as data then jQuery serializes the data using query string format, whereas the server is expecting JSON format directly.

    This happens despite telling jQuery to use JSON as the data type - it seems to only relate to the result, not the request payload sent to the server.

    Everything else you have there looks correct to me.

提交回复
热议问题