Put方法不是通过Ajax的谷歌浏览器 [英] Put method not working in Google Chrome through AJAX

查看:239
本文介绍了Put方法不是通过Ajax的谷歌浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个工作正常在Mozilla和IE浏览器,但由于某种原因没有镀铬。在镀铬,错误回调执行每一个返回零的误差code时间。很多对#1篇保持重申所有主流浏览器如何支持通过AJAX,而不是形式的PUT的方法。铬看来是例外.....

的JavaScript

 函数的工作(){警报(工作);} //只是一个成功的回调

    $(文件)。就绪(函数(){

    $(#crudForm)。递交(函数(){
        $阿贾克斯(网址:{url:/ UtilityDashboard / MeasurementNodes
            数据:parseFormData(crudForm),
            缓存:假,
            异步:假的,
            数据类型:文本,
            的contentType:应用程序/ x-WWW的形式urlen codeD,
            键入:放,
            成功:作品()
            错误:函数(XHR){警报(xhr.status + xhr.statusText);}});
    });

    });
 

HTML

 <形式ID =crudForm>
       名称和LT; BR />
       <输入类型=文本名称=名称/>< BR />< BR />
       节点ID< BR />
       <输入类型=文本名称=NODE_ID/>< BR />< BR />
       类型< BR />
       <输入类型=文本名称=输入/>< BR />< BR />
       家长和LT; BR />
       <输入类型=文本名称=PARENT_ID/>< BR />< BR />
       经度< BR />
       <输入类型=文本名称=经度/>< BR />< BR />
       纬度< BR />
       <输入类型=文本名称=纬度/>< BR />< BR />
       说明< BR />
       < textarea的名称=说明行=5COLS =40>此处测量节点&lt的插入说明; / textarea的>< BR />< BR />
       <输入类型=提交值=添加节点/>

    < /形式GT;
 

解决方案

那么的尤金 OhgodWhy 的是正确的。 Chrome浏览器确实有在XMLHTT prequest对象的放方法的支持!

解决方案

我遇到的问题就走了,当我停止使用提交事件来传达我的表单数据,而是依靠点击事件。这发生在哪里后提交的铬会追加表单变量,以当前的URL一些其他的问题,我有照顾。这很可能也已经解决了使用事件。preventDefault。

I have this working fine in Mozilla and IE but for some reason not chrome. In chrome, the error callback executes every time returning an error code of zero. Lots of articles on Stackoverflow keep reiterating how all major browsers support the "PUT" method through AJAX instead of forms. Chrome appears to be the exception.....

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>

解决方案

So Eugene and OhgodWhy were correct. Chrome does have support for the "put" method in the XMLHTTPRequest object!

Solution

The problem I was experiencing went away when I stopped using the "submit" event to transmit my form data, and instead relied on the "click" event. This took care of some other issues I was having where after submit chrome would append the form variables to the current URL. This could probably have also been solved by using event.preventDefault.

这篇关于Put方法不是通过Ajax的谷歌浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆