weixin_33670713 2018-04-18 16:21 采纳率: 0%
浏览 15

在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.

  • 写回答

1条回答 默认 最新

  • local-host 2018-04-18 17:51
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上