我开始使用zombiejs,但我有一些问题:
1。)如何测试ajax调用? 例如,我有php ajax动作(Zend)
public function ajaxSomeAction()
{
$oRequest = $this->getRequest();
if($oRequest->isXmlHttpRequest() === false || $oRequest->isPost() === false) {
throw new Zend_Controller_Action_Exception('Only AJAX & POST request accepted', 400);
}
//process check params...
}
我的zombiejs测试代码会抛出http 400。
2.。)fire jquery如何插入公共方法?例如,我有代码:
(function($) {
$.manager.addInvitation = function()
{
//some code ....
}
$.manager = function(options)
{
//some code
}
})(jQuery);
我试试:
Browser.visit(url, function(err, browser, status)
{
// not work
browser.window.jQuery.manager.addInviation();
// also not work
browser.document.jQuery.manager.addInvitation();
browser.window.$.manager.addInvitation();
browser.evaluate('$.manager.addInvitation();');
})
3.。)如何使用zombiejs修改标头?对于exmaple我想添加标头x-performace-bot:zombie1来请求使用访问方法发送
Browser = require('zombie');
Browser.visit(url, {debug:true}, function(err, browser, status)
{
//send request witch header x-performace-bot
});
答案 0 :(得分:0)
快速测试后(在zombie 0.4.21上):
广告1。
在您检查($oRequest->isXmlHttpRequest()
)时,如果请求是xml http请求,则必须指定(在zombie中)X-Requested-With
标头,其值为XMLHttpRequest
。
ad 2。
// works for me (logs jQuery function - meaning it's there)
console.log( browser.window.jQuery );
// that works to...
browser.window.$
您的代码必须是未定义的,或者您网页上的Javascript中还有其他一些错误。
广告3。 有一个标题选项,您可以像使用 debug 一样传递。