我正在尝试将我的元素的一个id发送到我的indexController,当它被点击时。试过不同的方式在网上寻求帮助,但没有运气。我的控制器没有从jQuery / Ajax接收数据。有人可以帮忙吗?
我的观点:index.phtml
j
我的控制器:indexController.php
def dubleIncrement(x):
x = x+2
return x
def increment(x):
x = x+1
return x
if __name__ == "__main__":
i = 0
j = 0
i = increment(i)
j = dubleIncrement(j)
print i
print j
我的jQuery / Ajax:shuffle.js
<body>
<div class="container">
<div class="row header-white">
<div>
<h1><span id="homepage">Shuffle Buddy</span></h1>
</div>
</div>
<div class="row" id="nav">
<ul>
<li><div class="libox" id="a">A</div></li>
<li><div class="libox" id="b">B</div></li>
<li><div class="libox" id="c">C</div></li>
<li><div class="libox" id="d">D</div></li>
<li><div class="libox" id="e">E</div></li>
<li><div class="libox" id="f">F</div></li>
<li><div class="libox" id="g">G</div></li>
<li><div class="libox" id="h">H</div></li>
<li><div class="libox" id="i">I</div></li>
<li><div class="libox" id="j">J</div></li>
<li><div class="libox" id="k">K</div></li>
<li><div class="libox" id="l">L</div></li>
<li><div class="libox" id="m">M</div></li>
<li><div class="libox" id="n">N</div></li>
<li><div class="libox" id="o">O</div></li>
<li><div class="libox" id="p">P</div></li>
<li><div class="libox" id="q">Q</div></li>
<li><div class="libox" id="r">R</div></li>
<li><div class="libox" id="s">S</div></li>
<li><div class="libox" id="t">T</div></li>
<li><div class="libox" id="u">U</div></li>
<li><div class="libox" id="v">V</div></li>
<li><div class="libox" id="w">W</div></li>
<li><div class="libox" id="x">X</div></li>
<li><div class="libox" id="y">Y</div></li>
<li><div class="libox" id="z">Z</div></li>
</ul>
</div>
<div class="row" id="wrapper">
<div id="jsCarousel">
<div class="subitems">
<?php
$_items = $this->items;
// $this->text = "hello";
// $this->controller->text = "Hello";
?>
<p class="innersub"><?php echo $_items ['item'] . "<br>"; ?></p>
</div>
<div class="subitems"></div>
<div class="subitems"></div>
<div class="subitems"></div>
<div class="subitems"></div>
<div class="subitems"></div>
<div class="subitems"></div>
<div class="subitems"></div>
<div class="subitems"></div>
<div class="subitems"></div>
<div class="subitems"></div>
<div class="subitems"></div>
<div class="subitems"></div>
<div class="subitems"></div>
<div class="subitems"></div>
</div>
</div>
<div class="row">
<div class="bxdetails">
<div class="subdetails">
<h4 style="text-align: center;"><b>Attributes</b></h4>
</div>
<div class="subdetails">
<h4 style="text-align: center;"><b>Behavior</b></h4>
</div>
</div>
</div>
</div>
</body>
答案 0 :(得分:1)
我刚编辑了你的脚本并使用了jquery ajax函数而不是javascript ajax。这是代码
<script type="text/javascript">
$(document).ready(function(){
$('.libox').click(function () {
var contentPanelId = $(this).attr("id");
alert(contentPanelId);
ajaxFunction(contentPanelId);
location.href = "/";
});
function ajaxFunction(contentPanelId) {
$.ajax({
url:'/index/test',
type: 'POST',
data: {id: contentPanelId},
success:function(data){
alert(data);
}
})
}
});