在Ajax中需要帮助

I have this code to POST value to main.php, with onclick function UserID will be called and value which is user_id should be changed based on selected value and load selected user_id in user_profile.php?ID=user_id

var USER_ID = 0;
function UserID(user_id)
{
USER_ID = user_id;
              $.ajax({
                  type: "POST",
                  url: "main.php",
                  data: {ID: USER_ID},
                  success: function(msg)
                  {
                    alert(USER_ID);
                    $('#user_profile_content').load('user_profile.php?ID=USER_ID #user_profile_content');
                  },
                  error: function()
                  {
                      alert("error");
                  }
              });
}

After success post, alert is showing with selected value, it means POST was successful but I don't know how to make user_profile.php?ID=USER_ID to be changed based on received value. It's not replace global variable USER_ID.

From what I understand you want to change the url route, try:

...
success: function(msg){
    window.location.href = `user_profile.php?${msg.id}`
    $('#user_profile_content').load(`user_profile.php?ID=${msg.id}
#user_profile_content`);
...
  1. ES6 template literals allow you to insert the returned value in a string.

  2. Window.location.href allows you to change the route on the browser (Frontend), I recommend you do it from the Backend if possible though.

  3. This answer assumes msg.id is the desired value that you want to pass since the contents of the response are not specified.