简体   繁体   English

一次调用两个函数

[英]Two functions in one call

I would like to know if it's possible to do something like that:我想知道是否有可能做这样的事情:

 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);}
            });

I need to call two different controller functions, one after the other.我需要一个接一个地调用两个不同的控制器函数。 In this way only the first one is executed.这样只执行第一个。

If you want to Execute the second request after the first one, you just need to make the request inside the Callback.如果你想在第一个请求之后执行第二个请求,你只需要在回调中发出请求。

 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);}
            });
});

The Problem of the only the first one get called can depend on the Library you are using that seems to be "x$".唯一第一个被调用的问题可能取决于您使用的似乎是“x$”的库。

 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 } ?>
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM