CasperJS don'我没有请求AJAX

CasperJS don't make my AJAX request

本文关键字:请求 AJAX don CasperJS      更新时间:2023-09-26

我有一个CasperJS错误。我正试图点击一个链接,那里有一个关于onclick的AJAX请求。AJAX请求从未发出。

这是我的index.php页面:

<html>
<head>
    <title>AJAX test</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js>
    </script>
    <script>
    function test(id){
        $.ajax({
            type: 'POST',
                data: {
                    'id': id
                },
                url: 'test.php',
                async: false
        });
        alert('OK');
        return true;
    }
</script>
</head>
<body>
    <a onclick="return test(1)" href="http://www.google.fr">www.google.fr</a>
</body>
</html>

我的测试.php页面:

<?php 
print_r($_POST['id']);
mail('mymail', 'Test AJAX', $_SERVER['REMOTE_ADDR'].' : '.$_POST['id']);
?>

还有我的CasperJS脚本:

var utils = require('utils');
var casper = require('casper').create({
verbose: true,
logLevel: "debug"
});
casper.start('http://www.example.com/index.php');
casper.thenEvaluate(function(term) {}, 'CasperJS');
casper.then(function() {
    this.click('a');
});
casper.then(function() {
    console.log('clicked ok, new location is ' + this.getCurrentUrl());
});
casper.run();

"alert"消息启动得很好,但AJAX请求没有启动。你知道为什么吗?

好的,我找到了答案。问题是因为我使用的是一个需要身份验证的代理,而AJAX请求没有发送所需的用户和密码。

我直接将代理配置为允许所有来自我的IP的连接,而无需身份验证,并且它可以工作。