JSON formatting (Sending JSON via jQuery AJAX post to Java/Wicket server)

前端 未结 1 369
轮回少年
轮回少年 2020-12-02 23:42

I\'m using jQuery to post JSON to a Java server, but I think my JSON must be wrong. Here\'s an example of my data and how I\'m sending it:

var lookup = {
            


        
相关标签:
1条回答
  • 2020-12-03 00:33

    You have to use JSON.stringify:

    $.ajax({
        type: 'post',
        data: JSON.stringify(lookup),
        contentType: 'application/json',
        dataType: 'json'
    });
    

    You should also specify 'application/json' as the contentType. By default jQuery will serialize objects with application/x-www-form-urlencoded (even if the contentType is application/json'). So you have to do it manually.

    EDIT: Key for 'post' should be type, not method.

    0 讨论(0)
提交回复
热议问题