javascript - PHP headers always give error Undefined Index even using $_SERVER global -


i performing ajax request cross domain. have been trying use functions return headers in array find undefined index though can return values in ajax request , print them screen.

i have found posts on said should using $_server globals. switched method same results.

here jquery:

settimeout(function() {                 jquery.ajax({                     url: 'http://something.com',                         type:"post",                     datatype:"json",                     crossdomain:true,                     contenttype:"application/json",                     data: jsondata,                     processdata:false,                     cache:false,                     beforesend: function( xhr ) {                         xhr.setrequestheader("authorization",api_key[index]);                         xhr.setrequestheader("action","push");                     },                     success: function(data) {                         alert(data.action);                         alert(data.platform + ' : ' + data.message + ' : ' +  data.app_name );                          if(data.message == 'success')                          {                             jquery('#hollmanpns_send_push div#hollmanpns_progressbar' + index).progressbar("value",100);                              //add message paragraph app name                             jquery('#hollmanpns_send_push p#hollmanpns_paragraph' + index).append(': complete');                          }                     },                     error: function(jqxhr, textstatus, errorthrown) {                         alert( 'we had error: ' + textstatus + errorthrown );                     }                 }).fail(function() {                     alert( 'we had failed ajax call.');                 });//end ajax              }, index * 5000);//end timeout function 

and here using php:

if($_server['http_action'] != '') { //do } 

i have tried switching to:

xhr.setrequestheader("x-action","push"); 

and

$_server['http_x_action'] 

with same results. not able return them ajax request.

i using php 5.3.3.

i using function change depending on different headers trying @ time:

header('access-control-allow-headers: action, authorization, content-type'); 

you'll want headers different way so:

$headers = getallheaders();  if(array_key_exists('action', $headers) && $headers['action'] != '') { //do } 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -