我尝试将post值发送到OrderController(我使用ZF2)。我在视图文件夹中有javascript代码。这些是代码:
function submitHandler(form) {
var urls = '<?php echo $this->baseurl; ?>/order/saveOrder';
var pack= $("#pack").val(),
name= $("#name").val(),
instit= $("#instit").val(),
telp= $("#telp").val(),
email= $("#email").val(),
address= $("#address").val(),
orderno = "test",
order_stat ="phone",
pack_type = "recurring",
rec_period ="monthly";
$.ajax({
type: 'POST',
url: urls,
data: {
pack: pack,
name: name,
instit:instit,
telp: telp,
email: email,
address: address,
orderno : orderno,
order_stat :order_stat,
pack_type : pack_type,
rec_period :rec_period
},
success: function(msg) {
var result = JSON.parse(msg);
if (result.success) {
alert("SUccESSSS");
} else {
alert(result.msg);
}
},
error: function(xhr, status, error){
alert("Failed");
}
});
}
这些是来自控制器的代码:
public function saveOrderAction() {
$post = $this->getRequest()->getPost();
$response = $this->getResponse();
/*
$storage = Order\Storage::factory($this->getDb());
$attd = new Order($storage);
$success = false;
$msg = '';
$attd->orderno = $post['orderno'];
$attd->order_stat = $post['order_stat'];
$attd->pack = $post['pack'];
$attd->pack_type = $post['pack_type'];
$attd->rec_period = $post['rec_period'];
$attd->name = $post['name'];
$attd->instit = $post['instit'];
$attd->telp = $post['telp'];
$attd->email = $post['email'];
$attd->address = $post['address'];
//$save = $attd->saveOrder();
if ($attd->saveOrder(true)) { */
$success = true;
$msg = 'Saved Success';
echo "<script type='text/javascript'>alert($msg);</script>";
print_r('test');
printf('test2');
$response->setContent(json_encode(array("success" => $success, "msg" => $msg)));
return $response;
}
但它并没有显示任何东西。所以我评论过,只是想表现出警觉,但它并没有表现出来。帮助我,谢谢。
答案 0 :(得分:0)
您可能需要将网址更改为:
var urls = '<?php echo $this->baseurl; ?>/order/save-order';
zend中的URL是小写的。破折号分隔多个单词。处理请求时,操作是camelCased,因此您的操作方法是正确的PSR-2。