gpt4 book ai didi

javascript - 通过 Nightmare js获取Ajax请求

转载 作者:行者123 更新时间:2023-12-03 13:23:31 25 4
gpt4 key购买 nike

所以,我正在使用 Nightmare js,并且我想模拟一个登录过程,为此我使用了 Nightmare js

function testiiing(){
nightmare
.goto('http://localhost:4200/login')
.type('#name', 'test')
.type('#pwd', 'test')
.click('#log')
.evaluate(function() {
return //something
})
.then(function(result) {
console.log(result);
})
.then(function() {
console.log('done');
})
.catch(function(error){
console.error('an error has occurred: ' + error);
});
}

问题是我想将“//something”更改为可以返回“name = test&pwd = test”的名称(因此,ajax post请求),有人可以帮助我还是告诉我是否可能?

最佳答案

没有使用 Nightmare js的经验,但是由于您已经标记了jQuery,只需使用.serialize()
https://api.jquery.com/serialize/

The .serialize() method creates a text string in standard URL-encoded notation. It can act on a jQuery object that has selected individual form controls, such as <input>, <textarea>, and <select>: $( "input, textarea, select" ).serialize();



例子:
$( "form" ).on( "submit", function( event ) {
event.preventDefault();
console.log( $( this ).serialize() );
});

这恰好可以满足您的需求。

对于您的特定示例,还请查看 .serializeArray()

关于javascript - 通过 Nightmare js获取Ajax请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42787348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com