I'm doing a basic jQuery ajax post to a targeted action. Each time it generates a notice.

Here's the jQuery ajax:

  $(function(){
    $('#greet').click(function(e){
      e.preventDefault();
      var name = $('#name');
      $.ajax({
        url: '/webservice/greetings/' + name.val() + '/sayhello',
        type: 'post',
        dataType: 'json',
        success: function(message){
          alert(message);
        }
      });
    });
  });

Here's the notice:

340 21/Nov 16:13 notice php Notice: Undefined index: CONTENT_TYPE in RESTServer->parseRequest() (line 261 of /home/ry/sites/dev/sites/all/modules/contrib/services/servers/rest_server/includes/RESTServer.inc).

Apparently $_SERVER['CONTENT_TYPE'] is not being set for some reason.

Comments

marcingy’s picture

Category: bug » support

You should be setting that header when you post the data. And why are you using rc5?

rylowry@gmail.com’s picture

Category: support » bug

If I add an empty data object, the notice disappears. My guess is that my first ajax post did not result in a request with a body, so there was no $_SERVER['CONTENT_TYPE']. It seems to me that posting to a targeted action without any body seems like it shouldn't generate a notice.

  $(function(){
    $('#greet').click(function(e){
      e.preventDefault();
      var name = $('#name');
      $.ajax({
        url: '/webservice/greetings/' + name.val() + '/sayhello',
        type: 'post',
        dataType: 'json',
        data: {},
        success: function(message){
          alert(message);
        }
      });
    });
  });
rylowry@gmail.com’s picture

I'm on rc5 because we don't immediately update to the latest version of our modules. We upgrade modules periodically. We happen to be on the version I mentioned in the report when I saw this notice.

marcingy’s picture

Status: Active » Closed (won't fix)

There should be content type being provided to the server, this is really a won't fix or if there is a bug it is upstream of services.

rylowry@gmail.com’s picture

I added

contentType: 'application/json',

That forces the header to be there even if the body is empty, which makes services happy. Thanks.

aspilicious’s picture

Status: Closed (won't fix) » Active

In deploy => plugins => DeployServiceRestJSON.inc the content_type got set.

$this->config['headers']['Content-Type'] = 'application/json';

I wonder why that is put inside the foreach...
Should also work outside of it, normaly...

Maybe it has to be contentType or CONTENT_TYPE or Content_Type...
You should try one of those.

aspilicious’s picture

Status: Active » Closed (won't fix)

wrong issue