0

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>
Usman Mutawakil
  • 4,993
  • 9
  • 43
  • 80
  • Check this out: http://stackoverflow.com/questions/3378894/html5-put-delete-methods-not-working-in-chrome – theintersect Sep 19 '12 at 06:37
  • 1
    Thanks but that article only applies to
    support for the "put" method. If you see above I'm submitting my data with AJAX. The article you just supplied says this should work in all browsers.
    – Usman Mutawakil Sep 19 '12 at 06:39
  • This works fine for me in Chrome. 21.0.1180.89 distribution. – Ohgodwhy Sep 19 '12 at 06:42
  • How do you know your actually sending the data to the server? For me, I can see the logs since the web server is local, so I know it's not working on my end with Chrome. If you have an alternate mechanism of viewing outgoing data I'm all ears. – Usman Mutawakil Sep 19 '12 at 06:44
  • @Ohgodwhy so you get no error message? – Usman Mutawakil Sep 19 '12 at 06:48
  • 1
    I know I'm sending data to the server because I changed the URL to my controller and checked for a put request. Although, it wouldn't matter. As long as the file is found, it will return successful; however, there will be no data for me to parse. Either way, worked for me. – Ohgodwhy Sep 19 '12 at 06:50
  • 1
    Some extension in Chrome may block your request, AdBlock Plus for example. – Eugene Sep 19 '12 at 07:08
  • @Ohgodwhy Cool. Thanks for testing it on your machine. I gotta poke around more then. – Usman Mutawakil Sep 19 '12 at 12:45
  • @Eugene Damn. I can reinstall chrome but it's going to be tricky controlling that for other users. Thanks. – Usman Mutawakil Sep 19 '12 at 12:56

1 Answers1

0

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.

Usman Mutawakil
  • 4,993
  • 9
  • 43
  • 80