获取隐藏元素并将其发送到不同的 URL

问题描述

我正在做一个挑战,它要求我获取元素的 ID(从源代码 - 它隐藏在那里 - 在我的示例中称为令牌),然后将其重新发送到包含 POST 请求的另一个页面。但是代码不会继续执行第二个请求(POST 请求),原因是它不会在控制台上抛出错误

var req = new XMLHttpRequest();
req.onload = handleResponse;
req.open('get','/example/ex1',true); // will open the page /example/ex1
req.send(); // sends the request
function handleResponse() {
    var token = this.responseText.match(/name="token" value="(\w+)"/)[1];
    var changeReq = new XMLHttpRequest();
    changeReq.open('post','/example/ex2',true);
    changeReq.send('token='+token+'&user=admin')
};

感谢您的帮助。

解决方法

检查网络标签。确保调用了目标 URL。