2012-09-19 44 views
0

我在Mozilla和IE中可以正常工作,但由於某種原因不能使用Chrome瀏覽器。在chrome中,每次返回錯誤代碼爲0時,都會執行錯誤回調。很多關於Stackoverflow的文章不斷重申所有主流瀏覽器如何通過AJAX而不是表單支持「PUT」方法。 Chrome似乎是例外.....通過AJAX無法在Google Chrome中使用的放置方法

的JavaScript

 function works(){alert("working");} // just a success callback 

    $(document).ready(function(){ 

    $("#crudForm").submit(function(){ 
     $.ajax({url:"/UtilityDashboard/MeasurementNodes", 
      data:parseFormData("crudForm"), 
      cache: "false", 
      async: "false", 
      dataType: "text", 
      contentType: "application/x-www-form-urlencoded", 
      type:"put", 
      success: works(), 
      error:function(xhr){alert(xhr.status + xhr.statusText);} }); 
    });  

    }); 

HTML

<form id="crudForm"> 
     Name<BR/> 
     <input type="text" name="name"/><BR/><BR/> 
     Node Id<BR/> 
     <input type="text" name="node_id"/><BR/><BR/> 
     Type<BR/> 
     <input type="text" name="type"/><BR/><BR/> 
     Parent<BR/> 
     <input type="text" name="parent_id"/><BR/><BR/> 
     Longitude<BR/> 
     <input type="text" name="longitude"/><BR/><BR/> 
     Latitude<BR/> 
     <input type="text" name="latitude"/><BR/><BR/>   
     Description<BR/>   
     <textarea name="description" rows="5" cols="40">Insert description of measurement node here</textarea><BR/><BR/>   
     <input type="submit" value="Add Node"/> 

    </form> 
+0

看看這個:http://stackoverflow.com/questions/3378894/html5-put-delete-methods-not-working-in-chrome – theintersect

+1

謝謝,但該文章只適用於

支持「put」方法。如果您在上面看到我正在使用AJAX提交我的數據。你剛剛提供的文章說這應該適用於所有瀏覽器。 –

+0

這在Chrome中適用於我。 21.0.1180.89分佈。 – Ohgodwhy

回答

0

所以尤金OhgodWhy是正確的。 Chrome確實支持XMLHTTPRequest對象中的「put」方法!

解決方案

我遇到的問題就走了,當我停止使用「提交」事件傳達我的表單數據,而是依靠「點擊」事件。這提供了一些其他問題,我在提交chrome後會將表單變量附加到當前URL。這可能也可以通過使用event.preventDefault來解決。