0
我在寻找你的帮助。我想用Magento中的Ajax更改头像图片。 我的形式没有AJAX的工作,这是默认的形式action="<?php echo $this->getUrl('customer/account/editProfile') ?>"
Magento编辑个人资料AJAX
这是我的代码:
<form id="avatarform" enctype="multipart/form-data" method="post">
<?php echo $this->getBlockHtml('formkey')?>
<input type="file" name="avatar"/>
<a><button type="submit" class="general-btn"><span><?php echo $this->__('Save Profile') ?></span></button></a>
</form>
而我的JS功能现在:
jQuery("#avatarform").submit(function(){
//alert ("test");
//jQuery.post('<?php echo $this->getUrl('customer/account/editProfile') ?>');
//return false;
url = '<?php echo $this->getUrl('customer/account/editProfile') ?>';
new Ajax.Request(url, {
parameters: {isAjax: 1, method: 'POST'},
onSuccess: function(transport) {
}
});
});
你对我有一个建议?
在此先感谢。
编辑:有了这个新代码,我可以获得成功警报。
jQuery('#avatar').live('change', function() {
//alert('test');
var boxval = jQuery("#avatar").val();
var dataString = 'avatar='+ boxval;
//document.avatarform3.submit();
jQuery.ajax({
type: "POST",
data: dataString,
cache: false,
url: "http://localhost/magento-sample/index.php/customer/account/editProfile",
success: function(html) {
alert('sucess');
}
});
});
但表格未提交。也许我会错过添加正确的数据/参数,但为什么我需要在Ajax中添加一些参数,当它与正常的请求模式一起工作时?我怎样才能找到正确的参数添加?
Thx。
你遇到过什么问题?这里真正的问题是什么? –
感谢您的关注。这很简单,我的JS功能不提交我的表单,我不知道为什么。 – Kaherdin
它是否不正确提交表单,因为您实际上没有在包含表单信息的'parameters'中提交任何内容?这里有一些很棒的Prototype AJAX教程:http://24ways.org/2005/easy-ajax-with-prototype – 1000Nettles