【发布时间】:2012-06-30 03:32:27
【问题描述】:
在人们扑倒我之前,我已经看到了这个帖子:How do I PHP-unserialize a jQuery-serialized form?
我的问题非常相似,但我的数据却大不相同。我正在使用 AJAX 调用来发布帖子,数据发布得很好(jQuery 是 1.7)。当用户单击几个链接并深入到此表单和 ajax 脚本时,表单和 AJAX 会动态加载。
AJAX 看起来像:(顺便说一句,我知道你应该对我们使用 .on() 但我似乎无法像我一样使用 .live() )
$('#ajaxCaptionForm').live('submit', function(e){
e.preventDefault();
$.ajax({
'type':'POST',
'data':{formData: $('#ajaxCaptionForm').serialize()},
'success':function(){
parent.$.fancybox.close();
}
});
}); // closing form submit
表格如下:
<form method="Post" action="localhost/controller" id="ajaxCaptionForm" name="ajaxCaptionForm">
<label for="Caption">Caption</label><input type="text" id="Caption" name="Caption" value="Leaf lesions.">
<label for="Keywords">Keywords</label>
<p>Please seperate keywords by a comma
<input type="text" id="Keywords" name="Keywords" value=""></p>
<input type="hidden" id="imageID" name="imageID" value="87595">
<input type="submit" value="Update Image" name="yt3" clicked="true">
</form>
序列化后的数据如下:(根据firebug)
formData=Caption%3DFruit%2Blesions.%26Keywords%3D%26imageID%3D87592
当我回应回应时,我得到了这个:
"Caption=Leaf+symptoms+of+++CCDV.&Keywords=&imageID=87655"
我的问题是:
- 关键字字段为空,即使我输入内容也是如此
- 当我更改内容时,标题字段不会在帖子中更改。
-
如何访问每个变量?标题、关键词和图片。 $_POST 也不起作用:
Yii::app()->request->getParam('imageID')
【问题讨论】:
-
首先live是贬值尝试委托..('body').delegate('#ajaxCaptionForm','submit', function(e){
-
On 不起作用 bcz 你的 jquery 版本尚未实现..你可以尝试委托
-
我也无法让代理工作。 .live 适用于我所有其他 ajax 加载的表单。
-
@ubercooluk:请正确英语。谢谢。 (即没有“bcz”和“ur”)
-
on在 1.7 中支持。他很可能只是没有正确使用它。