Ajax PUT returning error 500

Asked

Viewed 111 times

1

I did an ajax to use the PUT method to update the field of a table but the server (Rest) is returning me error 500 and I do not know what I’m doing wrong, someone can give me a light please?

Error that occurred: OPTIONS http://localhost:8081/datasnap/Rest/Tcadastros/Group/ 500 (Internal Server Error)

$(document).on('click', "#modalgravar", function(){
        var eUrl = "http://localhost:8081/datasnap/rest/TCadastros/Grupo/"; 
        var Ecdgrupo = $("#Cdgrupoedit").val();
        var Egrupo = $("#grupoedit").val();
        var eData ={Cdgrupo: Ecdgrupo, Grupos: Egrupo};


        $.ajax({type:"put",

                url: eUrl,
                    data: JSON.stringify(eData),
                contentType: "application/json",


                success: function(){
                    alert("Editado!");
                },
                error: function(){
                    alert("Erro:  O grupo não foi editado!");
                }
            }); 
    });  
  • What version of jQuery are you using?

  • I am very lay but I am using jquery-1.12.4.min. js, I believe it is version 1.12 right?

  • I think you should use PATCH and not PUT, PUT is for when you replace everything, PATCH when you replace part of the information, ie an update. Error 500 is from the server so you will need the log from there to know what is happening.

  • Which language you are using in the back end, the error is there, puts the back code, maybe not PUT support

  • @Leonardobarros Unfortunately I do not have access to the back code but I am absolutely sure that it supports the PUT. I believe that this error is happening because the server is not recognizing the call as put and returns this error but I’m not sure of anything, and if that’s right I can’t see where I’m going wrong.

  • You can really use PUT. It’s just that in the documentation it only mentions GET and POST. But I tested it here and it’s sending a string in JSON format, like: {"Cdgrupo":"2","Grupos":"5"}.

  • @rnd_rss I even thought about using the patch as well but I believe that the put would be the right one for my goal. But I can try to use the patch as well.

  • @Sam The return is the same but it happens only on the screen with me

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.