JQuery Post sends form data and not JSON

后端 未结 3 1895
终归单人心
终归单人心 2020-12-13 08:31

Trying to send json. Here\'s my function:

var object = ... ;

$.ajax({
      type: \'POST\',
      url: \'\',
      contentType: \'application/jso         


        
3条回答
  •  失恋的感觉
    2020-12-13 09:00

    With JSON.stringify(object)

    Sample:

    $.ajax({
        type: 'POST',
        url: '',
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        data: JSON.stringify(object)
    });
    

    Note JSON.stringify is not supported in all browsers (http://caniuse.com/#feat=json ), in particular browsers IE7 and lower.

    If you need to support this browsers too you can use this Javascript library: https://github.com/douglascrockford/JSON-js

提交回复
热议问题