【问题标题】:Two functions in one call一次调用两个函数
【发布时间】:2015-10-20 18:41:20
【问题描述】:

我想知道是否可以这样做:

 x$().xhr('<?php echo $this->createUrl('survey/index', array('id'=>$model->skey)); ?>', {
                method: 'POST',
                async: true,
                data: urlstringserialize(serialize(document.getElementById("token-form"))),
                callback: function() {respOK(this.responseText);}
            });
            x$().xhr('<?php echo $this->createUrl('survey/saveBrowser', array('id'=>$model->skey,'browser'=>$browser->getBrowser(),'platform'=>$browser->getPlatform())); ?>', {
                method: 'POST',
                async: true,
                data: urlstringserialize(serialize(document.getElementById("token-form"))),
                callback: function() {respOK(this.responseText);}
            });

我需要一个接一个地调用两个不同的控制器函数。这样只执行第一个。

【问题讨论】:

  • 你不是在为不可避免的注入攻击做好准备吗?
  • x$().xhr 到底是做什么的?
  • 你怎么确认>只执行第一个。
  • 你能告诉我们respOKx$()吗?
  • x$ 因为我用的是 xuijs。

标签: javascript jquery ajax yii xui


【解决方案1】:

如果你想在第一个请求之后执行第二个请求,你只需要在回调中发出请求。

 x$().xhr('<?php echo $this->createUrl('survey/index', array('id'=>$model->skey)); ?>', {
        method: 'POST',
        async: true,
        data: urlstringserialize(serialize(document.getElementById("token-form"))),
        callback: function() {
            respOK(this.responseText);
            x$().xhr('<?php echo $this->createUrl('survey/saveBrowser', array('id'=>$model->skey,'browser'=>$browser->getBrowser(),'platform'=>$browser->getPlatform())); ?>', {
                method: 'POST',
                async: true,
                data: urlstringserialize(serialize(document.getElementById("token-form"))),
                callback: function() {respOK(this.responseText);}
            });
});

唯一被调用的第一个问题可能取决于您使用的库,它似乎是“x$”。

【讨论】:

  • 我已经尝试过了,但它对我不起作用。无论如何,谢谢。
【解决方案2】:
 function respOK(data) {
        <?php if($browser->getBrowser() == Browser::BROWSER_IE) { ?>
        <?php if($campaignCenter->campaign_id == 326) { ?>
            x$("style").remove(".type");
        <?php } ?>
            x$('div.surveyform').html(data);
        <?php } else  { ?>
        <?php if($campaignCenter->campaign_id == 326) { ?>
            x$("style").remove(".type");
        <?php } ?>
            x$('div.surveyform').tween({opacity:0, duration: 200}, function() {x$('div.surveyform').html(data); x$('div.surveyform').tween({opacity: 1, duration: 200});});
        <?php } ?>
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-22
    • 2020-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多