weixin_33749131
weixin_33749131
采纳率0%
2017-08-29 09:32 阅读 152

URL中的“:”是什么意思?

我的一个学校项目要求将一些AJAX请求发送到服务器的url:

http://localhost:8000/messages/:id

在这里,我应该将id的值设置为唯一数字。我知道?表示查询搜索,#正如这里提到的,但是:是什么意思? 如果我将id值设置为等于123,它的显示方式是这个 http://localhost:8000/messages/:123 ,还是 http://localhost:8000/messages/123?

任何帮助都将不胜感激!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • weixin_33696106 weixin_33696106 2017-08-29 09:37

    The third : in the URL you presented is just a placeholder indicating that id is a variable name. Therefore, :id must be replaced by a value, for example 123.

    Your second attempt answer is correct.

    点赞 评论 复制链接分享
  • weixin_33670786 weixin_33670786 2017-08-29 09:40

    There are two ':' in your url. The first one separates the host from the port e.g. host:port - in your case the host is localhost, the port is 8000.

    Second case, ':id', specifies that the id is a variable. It can be replaced by any value such as '123'. The notation is there so you can differentiate a string in the url (../messages/id) from the usage of variables (../messages/:id).

    All in all you have to drop the : in usage as you insert a value for the variable.

    点赞 评论 复制链接分享

相关推荐