2012-10-08 44 views
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。

+2

你遇到過什麼問題?這裏真正的問題是什麼? –

+0

感謝您的關注。這很簡單,我的JS功能不提交我的表單,我不知道爲什麼。 – Kaherdin

+0

它是否不正確提交表單,因爲您實際上沒有在包含表單信息的'parameters'中提交任何內容?這裏有一些很棒的Prototype AJAX教程:http://24ways.org/2005/easy-ajax-with-prototype – 1000Nettles

回答

0

如何閱讀表單提交時的參數,使用post方法時需要讀取請求參數。

相關問題