1

I am trying to make a jQuery POST request from a locally hosted web-page to a locally hosted server.

My server listens at When I send a POST request using my HTTP client, I receive a 201 created response, as I expect.

Now, I try to send the same request using jQuery:

function postAppointment() {

    $.post({
        url:'http://localhost:8085/appointments',
        data: appointmentFactory(),
        crossDomain: true,
        headers: {
            'Content-Type' : 'application/json',
            'Accept' : 'application/json'

        }
    });
}

I receive the following error message from the Safari error console:

[Error] Failed to load resource: the server responded with a status of 501 (Not Implemented) ([object Object], line 0)

However, I'm not so sure the server is actually responding, because I have tried sending the requests to netcat and it is not printing out any requests, while if I use my GUI HTTP client, netcat does print out the requests.

So... to me this seems to be a client-side issue, since my backend-service is confirmed to be working by my GUI HTTP client. I thought maybe this problem has to do with how I am serving my page, so I have tried serving the page:

  1. Opening directly from the Finder
  2. Opening via IDE link which seems to run a server (JetBrains WebStorm)
  3. python -m SimpleHTTPServer

Is there a client-side configuration I am missing which is preventing me from sending a request?

Thanks for any help.

And in case you are wondering, appointmentFactory() returns

Object
eventName: "Fiesta Forever"
phoneNumber: "13125555555"
time: Thu Dec 18 2014 17:15:00 GMT-0600 (CST)
__proto__: Object

And I have also sent the request by parsing the object with JSON.stringify().... I'm not sure if that is done automatically.

I also tried the request via Desktop Chrome, and received the following additional information: enter image description here

Thanks again for any help.

-Blake

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Blake G
  • 581
  • 7
  • 24
  • Might be duplicate of this:http://stackoverflow.com/questions/3121451/why-do-i-get-this-501-not-implemented-error – Patrick C Dec 18 '14 at 22:27
  • `data` cannot simply be a JavaScript object otherwise jQuery will encode it using URL encoding (`name=value&...`) -- it doesn't check the content type. You need to serialize it into a JSON string manually. – Cameron Dec 18 '14 at 22:27
  • Thanks Cameron, I will send future requests using JSON.stringify()... I wasn't sure if this was done automatically. – Blake G Dec 18 '14 at 22:29
  • Regarding JSONP, are the client and server considered to be on a different domain if they are both running on localhost? – Blake G Dec 18 '14 at 22:53

0 Answers0