リダイレクトしたいとき、変数whereは常にudefinedです。しかし、たとえば、その変数を入れて、alert();
正しい数値を表示したいと思います。
コード
var where = msg.txt;
window.location = "/page.php?id=".where; //this redirects to /page.php?id=undefined
alert(where); //it show correct number
リダイレクトしたいとき、変数whereは常にudefinedです。しかし、たとえば、その変数を入れて、alert();
正しい数値を表示したいと思います。
コード
var where = msg.txt;
window.location = "/page.php?id=".where; //this redirects to /page.php?id=undefined
alert(where); //it show correct number
そのはず:
window.location = "/page.php?id=" + where;
あなたが持っている:
"/page.php?id=".where;
where
文字列のプロパティを取得しようとしますが、そのようなものは定義されていません。
JavaScriptでは.
、PHPのように文字列を連結するためではなく、プロパティへのアクセスに使用されます。
+
代わりに使用してください:
window.location = "/page.php?id=" + where;