2012-09-19 39 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来解决。