jQuery POST到CakePHP $ this->数据 [英] jQuery POST to CakePHP $this->data
本文介绍了jQuery POST到CakePHP $ this->数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用jQuery的后功能将表单发布到CakePHP脚本中.
I'm trying to use jQuerys post-function to post a form to a CakePHP-script.
喜欢这个:
jQuery:
$('#submit_btn').click(function(){
//Code to prevent redirect
dataString = 'test=testdata';
$.post('cakephp/forms/output', dataString, function(response){
alert(response);
})
});
CakePHP
function output(){
pr($this->data); # Print nothing
pr($_POST); # Print test => testdata
$this->render('view','ajax'); # Render ajax-friendly
}
所以$_POST
不是空的,但是$this->data
是...怎么了?
So $_POST
isn't empty but $this->data
is... how come??
要发布数据的表单元素i是从aja获取的,如果在这种情况下这很重要的话.
The form element i which to post data from is got from aja, if that is something that matters in this case.
推荐答案
$ this-> data期望您的变量名采用以下格式
$this->data expects your variable names to be in the form
data[Model][Property]
在您的示例中,将dataString更改为data['ModelName']['test']=test data
For your example change dataString to data['ModelName']['test']=test data
它应该可以工作.
这篇关于jQuery POST到CakePHP $ this->数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文