简体   繁体   中英

how can I set the post path in javascript jquery with java spring

I am working on the jquery code which has REST API call,

In my javascript, clicky.js

button.click(function (){
  $.post('/projectFolder/workbook/createWorkbook', {}, function(){
    // do somthing
    }
  ) ....

My spring project structure is,

projectFolder
|- src
    |-main
       |-java
       |   |-com.sample.workbook
       |              |-controller
       |              |-service
       |                  |-WorkbookService
       |                  |-WorkbookServiceImpl
       |-webapp
            |-package.json
            |-clicky.js
            |-index.html

My package.json

I use npm start inside of webapp folder to launch it locally.

In server side, it is working fine. However, when I debug it locally, I get 404 error that it cannot find projectFolder path.

How can I set its path in javascript, so that I can debug locally?

Thanks in advance

'/projectFolder' is most likely the application context you're deploying to. This can be set in your IDE, but best practice is to create a web-app without assuming a given context. So, change your call to

$.post('workbook/createWorkbook', {}, function(){

note not only the missing '/projectFolder', but also that the URL does not have a leading slash, ie. is relative to your HTML page's URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM