2013-08-21 55 views
2

我有一個CasperJS的錯誤。我試圖點擊一個鏈接,在onclick上有一個AJAX請求。 AJAX請求從未做出。CasperJS不會讓我的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> 

我的test.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(); 

「警報」 消息很好的啓動,但不是AJAX請求。你知道爲什麼嗎 ?

回答

0

好吧,我找到了答案。問題是因爲我正在使用需要驗證的代理,並且AJAX請求未發送所需的用戶和密碼。

我直接配置代理以允許來自我的IP的所有連接而無需驗證,並且它可以工作。