从静态向控制器发送HTTP请求

时间:2018-07-14 09:40:02

标签: ajax spring-boot

我正在使用Spring Boot应用程序。我有一个resources/static/index.html页面,其中包含以下ajax请求:

$.ajax({
    type: "POST",
    url: '/create',
    data: {content: content}
});

当我点击按钮时,我执行它,当我点击它时,我在地址栏中得到以下URL:

http://localhost:8080/?content=newPaste

由于某些原因/create丢失。为什么这样?在我的情况下,指定URL的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

您需要将数据作为字符串发送。试试这种方法:

$.ajax({
   type: "POST",
   url: '/create',
   contentType: "application/json",
   dataType : 'json',
   data: JSON.stringify({content: content})
});
相关问题