How can I send JSON data to server

前端 未结 7 992
旧巷少年郎
旧巷少年郎 2021-01-04 00:25

Well, here is the story:

I have some data need to send to server, but they should turned into JSON dataType first.

I made such ajax call:

            


        
相关标签:
7条回答
  • 2021-01-04 01:19

    I've had the same problem. You can't send an object as "data", you need to stringify the object. Try this instead, with your object stringified:

    $.ajax({
           url: url,
           type: 'POST',
           contentType:'application/json',
           data: '{
              name:"test",
              key:"foo",
              key2:"bar"
           }',
           dataType:'json'
    });
    
    0 讨论(0)
提交回复
热议问题