ZendFramework Ajax jQuery post
您好,我在ZendFramework中有一个关于jQuery ajax post请求的问题,这是我的jQuery:ZendFramework Ajax jQuery post,jquery,ajax,zend-framework,http-post,Jquery,Ajax,Zend Framework,Http Post,您好,我在ZendFramework中有一个关于jQuery ajax post请求的问题,这是我的jQuery: $("input[type=image].addToCartButton").click(function() { var productId = $(this).attr("id"); $.ajax({ type: 'POST', dataType: 'html', url: "http://localhost/Z
$("input[type=image].addToCartButton").click(function() {
var productId = $(this).attr("id");
$.ajax({
type: 'POST',
dataType: 'html',
url: "http://localhost/ZendProjects/essence/essenceZP/public/order",
data: {
id: productId
},
success: function(data){
alert(data);
}
});
});
这是我在ZendFramework订单控制器中的代码:
$request = $this->getRequest();
if($request->isXmlHttpRequest()) {
$this->_helper->layout()->disableLayout();
$test = 'testing ajax content';
$this->view->test = $test;
} else {
$test = 'testing non-ajax content';
$this->view->test = $test;
}
在firebug控制台中,我收到一个错误,但看不到错误在哪里,因为它显示0.5秒并隐藏。。有什么想法吗?其思想是当您单击按钮将productId发送到订单控制器并将其放入会话数组中时,但目前仅测试ajax请求
标记:
<form action="" method="post">
<label for=".productQuantity" style="float: left;margin-top:7px;margin-left: 5px">Количество</label>
<input class="productQuantity" name="productQuantity" type="number" value="1" min="1" max="1000" style="width: 50px;float: left;margin-left: 7px" />
<input type="image" id="<?php echo $product->id; ?>" name="<?php echo $this->url(array('controller' => 'order', 'action' => 'add-to-cart'), 'default', true) ?>" src="<?php echo $this->baseUrl('images/cartPut.png'); ?>" style="margin-left: 13px;" />
</form>
Количество
发生的情况是,当您单击submit按钮时,ajax调用会在表单提交的同时触发
您可能想知道,如果没有action=”“
,为什么要提交表单
问题是,当action属性为空时,它假定它位于同一页上。我的意思是,如果您在localhost/index.php
上,那么action=”“
=action=“localhost/index.php”
因此,必须通过添加action=“javascript:void(0)”
禁用表单提交
您还可以使用jQuery进行以下操作:
甚至是普通javascript(提交事件返回false)发生的情况是,当您单击提交按钮时,ajax调用会在提交表单的同时触发
您可能想知道,如果没有action=”“
,为什么要提交表单
问题是,当action属性为空时,它假定它位于同一页上。我的意思是,如果您在localhost/index.php
上,那么action=”“
=action=“localhost/index.php”
因此,必须通过添加action=“javascript:void(0)”
禁用表单提交
您还可以使用jQuery进行以下操作:
甚至是普通javascript(提交事件返回false)我认为该按钮正在执行回发并取消ajax请求。。按下按钮markup@AshirvadSingh这是我的markup@FretwoakDukov试试这个
或者这个谢谢@keyne!!!!使用javascript:void(0)有效!:]]你能解释一下到底发生了什么吗?@FretwoakDukov我把它作为一个答案贴了出来。我想那个按钮正在做回发和取消ajax请求。。按下按钮markup@AshirvadSingh这是我的markup@FretwoakDukov试试这个
或者这个谢谢@keyne!!!!使用javascript:void(0)有效!:]]“你能解释一下到底发生了什么吗?”弗雷特沃克杜科夫说,我把它作为一个答案贴了出来。