AJAX调用转到文件位置,而不是实际URL

I have created a html JS project. I am calling AJAX function with URL but in the browser console, I see URL as Request URL: file:///C:/localhost:8080/allProducts

I want to call localhost:8080/allProducts

程式码片段:

$.ajax({
  url: '/localhost:8080/allProducts',
  ....
  ..
评论
  • 娃哈哈
    娃哈哈 回复

    I would remove the localhost:8080 portion of the URL. Assuming allProducts is some sort of file in the root directory, I would put url: /allProducts.

    Then, if you end up pushing this into a production server it will look for allProducts at the root directory level, no matter the hostname.

  • 大宝剑
    大宝剑 回复

    您需要如以下示例中所述指定协议:

    http:///localhost:8080/allProducts