2014-04-30 29 views
0

我目前深化發展一個新的網站不可能上的Prestashop

當我試圖創建一個帳戶創建一個新帳戶,我得到這樣的錯誤:

Uncaught TypeError: Cannot read property 'hasError' of null. 

這是代碼

function submitFunction() 
    { 
    $('#create_account_error').html('').hide(); 
    //send the ajax request to the server 
    $.ajax({ 
     type: 'POST', 
     url: baseUri, 
     async: true, 
     cache: false, 
     dataType : "json", 
     data: { 
      controller: 'authentication', 
      SubmitCreate: 1, 
      ajax: true, 
      email_create: $('#email_create').val(), 
      back: $('input[name=back]').val(), 
      token: token 
     }, 
     success: function(jsonData) 
     { 
      if (jsonData.hasError()) 
      { 
       var errors = ''; 
       for(error in jsonData.errors) 
        //IE6 bug fix 
        if(error != 'indexOf') 
         errors += '<li>'+jsonData.errors[error]+'</li>'; 
       $('#create_account_error').html('<ol>'+errors+'</ol>').show(); 
      } 
      else 
      { 
       // adding a div to display a transition 
       $('#center_column').html('<div id="noSlide">'+$('#center_column').html()+'</div>'); 
       $('#noSlide').fadeOut('slow', function(){ 
        $('#noSlide').html(jsonData.page); 
        // update the state (when this file is called from AJAX you still need to update the state) 
        bindStateInputAndUpdate(); 
        $(this).fadeIn('slow', function(){ 
         document.location = '#account-creation'; 
        }); 
       }); 
      } 
     }, 
     error: function(XMLHttpRequest, textStatus, errorThrown) 
     { 
      alert("TECHNICAL ERROR: unable to load form.\n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 
     } 
    }); 
} 

它似乎是jsonData,在功能上,這是行不通的。任何想法或建議?

+0

嘗試'如果(jsonData && jsonData.hasError && jsonData.hasError())' – Dom

+0

不工作,我得到了一個空白頁面+ 「遺漏的類型錯誤:空的無法讀取屬性 '頁'」 – Mathiewz

回答

2

成功處理程序將傳遞從ajax請求返回的數據。

它不會有一個叫hasError()的函數,因爲它只是一個json對象,它不會有任何功能。如果即如果Ajax調用返回一個HTTP 500

我不熟悉與PrestaShop HTTP錯誤

錯誤處理程序應該被解僱,但看在prestashop documentation hasError返回一個布爾(不是函數),所以請嘗試(沒有括號)。

if (jsonData.hasError)

您可能還需要檢查是否首先返回的任何數據。

if (jsonData)

+0

我確實刪除了括號,它會更好,但仍然存在相同的問題... – Mathiewz

+0

聽起來好像您的ajax調用沒有返回任何數據。 'if(jsonData)'將首先檢查。如果出現服務器端錯誤,我希望它會放入錯誤函數中。也許可以使用瀏覽器開發工具的網絡選項卡(chrome toolbar,firebug等)來查看ajax請求正在做什麼。 –