0

Hello I got a service that is made for sending html mails, it will be called from a method "SendMail(data) about 1500 characters.

I access the service though JQuery with AJAX call and JSON:

       var data = encodeURIComponent(JSON.stringify(dataArray));

                    $.ajax({
                        type: "GET",
                        url: "http://localhost:53334/Service.svc/SendMail?data=" + data,
                        contentType: 'application/json; charset=utf-8',
                        dataType: "json",
                        success: function () {
                            alert("Reklamationen er blevet sendt!");
                        },
                        error: function (err) {
                            alert("Kunne ikke sende reklamation! Der opstod en fejl.");
                        }
                    });

I got alot of fields and if I fill everything out it gives a 404 not found response but then if I leave some random fields empty it gets to the API and executes the method it should? So I think its about the data size. I have tried many settings in webconfig but i havent managed to find a solution.

I hope there will be someone who can help me.

waleedansari
  • 197
  • 1
  • 2
  • 16
martin
  • 1
  • 1
  • You put your `type` on the `ajax` call as **GET**, shouldn't that be a **POST** since you are not retrieving any data it seems. – Tikkes May 20 '15 at 11:29
  • Hmm i always use get, as I remember then i cant make post working with the service. But maybe i should try doing a post instead. :) – martin May 20 '15 at 11:38

1 Answers1

1

You should really be using POST as indicated by Tikkes. Semantically you aren't requesting a resource from the server, so GET doesn't make sense. Also, as noted here there is a maximum length that is enforced for Urls which is what GET uses to pass params(as you can see in your code as well). POST on the other hand uses the request body to send its data. Also, as noted here POST and GET sizes are usually configurable on the server, but POST is generally much larger(2KB vs 10MB defaults) as stated in one of the answers. Hope this helps.

Community
  • 1
  • 1
peinearydevelopment
  • 11,042
  • 5
  • 48
  • 76