Lar*_*son 3 jquery post cakephp-1.3
我正在尝试使用jQuerys post-function将表单发布到CakePHP脚本.
像这样:
jQuery的:
$('#submit_btn').click(function(){
//Code to prevent redirect
dataString = 'test=testdata';
$.post('cakephp/forms/output', dataString, function(response){
alert(response);
})
});
Run Code Online (Sandbox Code Playgroud)
CakePHP的
function output(){
pr($this->data); # Print nothing
pr($_POST); # Print test => testdata
$this->render('view','ajax'); # Render ajax-friendly
}
Run Code Online (Sandbox Code Playgroud)
所以$_POST不是空的但是$this->data......怎么样?
发布数据的表单元素i来自aja,如果这是在这种情况下重要的事情.
小智 5
$ this-> data期望您的变量名称在表单中
data[Model][Property]
Run Code Online (Sandbox Code Playgroud)
对于您的示例,将dataString更改为 data['ModelName']['test']=test data
它应该工作.
| 归档时间: |
|
| 查看次数: |
6145 次 |
| 最近记录: |