2009-08-16 84 views
1

我有一個JQuery/Ajax更新。它在所有主流瀏覽器中正確更新,但是,處理錯誤響應在任何版本的IE中都不起作用。Jquery/AJAX響應 - 在FF/Safari中工作,但不是IE parseFloat(html)問題?

繼承人的AJAX提交代碼:

$('.ajax_multi_submit').click(function (event) { 
     // if javascript is enabled, stop default post 
     event.preventDefault(); 

     // get the id assigned to this form. This id will 
     // be added to every id to used in processing 
     var element = $(this); 
     var Id = element.attr("id"); 
     var formUrl = $('#ajax_multi_form' + Id).attr('action'); 

     $.ajax({ 
      url: formUrl, 
      type: "POST", 
      dataType: "html", 
      data: $('#ajax_multi_form' + Id).serialize(), 
      beforeSend: function() { 
       showAjaxMultiBusy(Id); 
      }, 
      complete: function() {}, 
      success: function (html) { 
       processAjaxMultiForm(html, Id); 
      } 
     }); 
    }); 

同樣,我不認爲這個問題是在這裏,因爲所有的瀏覽器可以正常發佈更新。然而,處理與此代碼的結果時:

function processAjaxMultiForm(html, Id) { 
     $('#ajax_errors' + Id).hide('slow'); 
     window.setTimeout(function() { 
      $('#ajax_busy' + Id).hide('slow'); 
      if (parseFloat(html)) { 
       $('#ajax_message' + Id).html('Record Saved.').show('normal'); 
       $('#ajax_message' + Id).hide('slow'); 
      } else { 
       $('#ajax_errors' + Id).html(html).show('slow'); 
      } 
     }, 1500); 
    } 

當返回而不是整數的誤差串(parseFloat(HTML)=「一些串...」),FF和Safari正確顯示在錯誤「其他」條件。

無論返回值如何(1 =成功,字符串=錯誤),IE始終顯示「if」條件。

我假設一些天才會立即看到問題嗎?

編輯------- 這裏有一些信息。我在腳本中添加了一個控制檯日誌來輸出html變量。我在錯誤上得到了一個正確的字符串,成功的時候是「1」。我已經更新每一個建議下面的代碼到:

function processAjaxMultiForm(html, Id) { 
    $('#ajax_errors' + Id).hide('slow'); 
    window.setTimeout(function() { 
     $('#ajax_busy' + Id).hide('slow'); 
     console.log("html is: " + html); 
     if (isNaN(html)) { 
      $('#ajax_errors' + Id).html(html).show('slow'); 
     } else { 
      $('#ajax_message' + Id).html('Record Saved.').show('normal'); 
      $('#ajax_message' + Id).hide('slow'); 
     } 
    }, 1500); 
} 

和以前一樣,將按預期在FF Safari瀏覽器,但IE計算兩個字符串(錯誤)和整數(成功)作爲「成功」

回答

1

isNan應該工作。

+0

感謝嘗試沒!不工作 我換了isNAN建議(見下文)。適用於safari和FF工作正常。不能在IE8中工作。還沒有嘗試過6或7。 IE顯示「record saved」,無論是否成功 if(isNaN(html)){('#ajax_errors'+ Id).html(html).show('slow'); \t \t \t \t \t \t}其他{ \t \t $( '#ajax_message' +編號)的.html( '記錄保存。')顯示( '正常')。 \t $('#ajax_message'+ Id).hide('slow'); \t \t} – pdxtim 2009-08-16 21:48:30

+0

我剛剛在IE瀏覽器中用開發工具(工具 - >開發工具)嘗試過isNaN(「abc」)和isNaN(「123」),我得到了預期的結果(分別爲true和false) – 2009-08-16 22:10:30

+0

感謝您的幫助。我在上游發現了一個錯誤。我不明白爲什麼它會影響字符串與整數的評估,但是上游的改變讓這個消失。謝謝 – pdxtim 2009-08-17 01:52:55

1

如何努力(isNan(parseFloat(HTML))

編輯:。

或者你爲什麼不回 「成功」,在清晰度,以幫助

+0

感謝您的幫助! – pdxtim 2009-08-17 01:53:28

相關問題