Adding a parameter to the URL with JavaScript

后端 未结 30 2765
刺人心
刺人心 2020-11-22 07:33

In a web application that makes use of AJAX calls, I need to submit a request but add a parameter to the end of the URL, for example:

Original URL:

30条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 07:50

    This is very simple solution. Its doesn't control parameter existence, and it doesn't change existing value. It adds your parameter to end, so you can get latest value in your back-end code.

    function addParameterToURL(param){
        _url = location.href;
        _url += (_url.split('?')[1] ? '&':'?') + param;
        return _url;
    }
    

提交回复
热议问题