【问题标题】:Zombiejs how using with specifity situationsZombie Js 如何在特定情况下使用
【发布时间】:2012-08-24 20:50:46
【问题描述】:

我开始使用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.) 如何触发 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 修改标题?例如,我想添加标头 x-performace-bot:zombie1 以请求使用访问方法发送

Browser = require('zombie');
Browser.visit(url, {debug:true}, function(err, browser, status) 
{
    //send request witch header x-performace-bot
});

【问题讨论】:

    标签: node.js zombie.js


    【解决方案1】:

    经过快速测试(在僵尸 0.4.21 上):

    广告 1。 当您检查 ($oRequest->isXmlHttpRequest()) 请求是否为 xml http 请求时,您必须指定(在僵尸中)X-Requested-With 标头,其值为 XMLHttpRequest

    广告 2.

    // works for me (logs jQuery function - meaning it's there)
    console.log( browser.window.jQuery );
    // that works to...
    browser.window.$
    

    您的代码必须未定义,或者您的页面上的 Javascript 中存在其他一些错误。

    广告 3。 有一个 header 选项,您可以像使用 debug 一样传递它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多