gpt4 book ai didi

php - CakePHP w/jQuery (Javascript/Ajax) 简单链接和更新 - 我做错了什么?

转载 作者:行者123 更新时间:2023-12-02 20:12:50 25 4
gpt4 key购买 nike

我只是尝试使用 jQuery 打印出操作的内容。但我无法让我的 div 使用回显的内容进行更新。我做错了什么?

birds_controller.php

...
var $helpers = array('Js', 'Html', 'Ajax');
var $components = array('RequestHandler');

function birds_ajax_1() {
function birds_ajax_1_func_1() {
$this->autoRender = false;
echo "Text from Ajax clickaroo.";
}
}
...

birds_ajax_1.ctp

<?php
echo $ajax->link('Ajax Link', array('controller' => 'birds',
'action' => 'birds_ajax_1_func_1'),
array('update' => 'ajax_div', 'complete' => 'alert("Ok.")'));
?>

<div id="ajax_div"></div> <!-- echoed text is not showing here? -->

默认.ctp

...
echo $this->Html->script('jquery'); // Yes. My jQuery is being pulled in OK.
...

...
echo $this->Js->writeBuffer();
...

这是转储到我的来源的内容:

...
<a href="/php/cake_app_birds_v1.3/birds/birds_ajax_1_func_1" id="link2019467549" onclick=" event.returnValue = false; return false;">link1</a><script type="text/javascript">

//<![CDATA[
Event.observe('link2019467549', 'click', function(event) { new Ajax.Updater('ajax_div','/php/cake_app_birds_v1.3/birds/birds_ajax_1_func_1', {asynchronous:true, evalScripts:true, onComplete:function(request, json) {alert("Ok.")}, requestHeaders:['X-Update', 'ajax_div']}) }, false);
//]]>

最佳答案

birds_controller.php

var $helpers = array('Js' => array('Jquery'), 'Html', 'Ajax');
var $components = array('RequestHandler');

function birds_ajax_1() {
if ($this->RequestHandler->isAjax()) {
$this->render('/elements/birds_ajax_1'); // this birds_ajax_1.ctp contains the output into the #ajax_div.
}
}

birds_ajax_1.ctp

<?php
// Note I am not using the $ajax->link(...
echo $this->Js->link('Ajax Link', array('controller' => 'birds',
'action' => 'birds_ajax_1'), array('update' => '#ajax_div'));

?>

<div id="ajax_div"></div>

default.ctp 中没有任何变化。

希望这对其他人可能正在经历我刚刚经历的困惑有所帮助!很高兴我找到了光!现在进行一些 jQuery 排序?天啊。

关于php - CakePHP w/jQuery (Javascript/Ajax) 简单链接和更新 - 我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6756916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com