首页 > 解决方案 > 将变量传递给 window.location.replace 以进行重定向

问题描述

我试图在函数成功后将我的页面重定向到另一个页面,但它没有读取我在 window.location.replace 中的变量。

 var thenum = client.replace( /^\D+/g, '');
    $.ajax({
      url: '/signature_pad.php',
      type: 'POST',
      data: {
        imageData: imagen,
        id: thenum,
      },

    })
        .done(function (msg) {
          // Image saved successfuly.
          window.location.replace('http://something.com/show.php?id=${ thenum }');
        })
        .fail(function (msg) {
          console.log("error: " + msg);
        });

有什么方法可以将我重定向到http://something.com/show.php?id=${ num } 它必须将变量传递给 id

标签: javascriptjqueryjson

解决方案


需要改变

window.location.replace('http://something.com/show.php?id=${ thenum }');

window.location.href = ('http://something.com/show.php?id=' + thenum);

推荐阅读