【问题标题】:Put method not working in Google Chrome through AJAX通过 AJAX 在 Google Chrome 中放置方法不起作用
【发布时间】:2012-09-26 22:25:16
【问题描述】:

我在 Mozilla 和 IE 中可以正常工作,但由于某种原因不是 chrome。在 chrome 中,每次返回错误代码为零时都会执行错误回调。 Stackoverflow 上的许多文章不断重申所有主流浏览器如何通过 AJAX 而不是表单来支持“PUT”方法。 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>

【问题讨论】:

  • 谢谢,但该文章仅适用于
    对“put”方法的支持。如果您在上面看到我正在使用 AJAX 提交我的数据。您刚刚提供的文章说这应该适用于所有浏览器。
  • 这在 Chrome 中对我来说很好用。 21.0.1180.89 分布。
  • 我知道我正在向服务器发送数据,因为我更改了控制器的 URL 并检查了 put 请求。虽然,也无所谓。只要找到文件,就会返回成功;但是,将没有数据可供我解析。无论哪种方式,都为我工作。
  • Chrome 中的某些扩展程序可能会阻止您的请求,例如 AdBlock Plus。

标签: javascript jquery ajax rest google-chrome


【解决方案1】:

所以 EugeneOhgodWhy 是正确的。 Chrome 确实支持 XMLHTTPRequest 对象中的“put”方法!

解决方案

当我停止使用“提交”事件来传输表单数据并转而依赖“点击”事件时,我遇到的问题就消失了。这解决了我在提交 chrome 后将表单变量附加到当前 URL 时遇到的一些其他问题。这可能也可以通过使用 event.preventDefault 来解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-20
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-01
    • 1970-01-01
    相关资源
    最近更新 更多