anchor.diff:              {true, []} ->
                   {loop, Req, HttpState, hibernate};
               _ ->
  -                {ok, Req1} = reply_messages(Req, Messages, Config, true, Version),
  +                {ok, Req1} = reply_messages(Req, Messages, Config, true, Version, JsonP),
                   {ok, Req1, HttpState}
           end
       catch
           exit:{noproc, _} when Version =:= 1 ->
               {CookieIo, _} = cowboy_req:cookie(<<"io">>, Req),
  -            {ok, RD} = cowboy_req:reply(200, stream_headers(CookieIo), encode_polling_packets_v1(Protocol:encode_v1(disconnect)), Req),
  +            {ok, RD} = cowboy_req:reply(200, stream_headers(CookieIo), encode_polling_xhr_packets_v1(Protocol:encode_v1(disconnect)), Req),
               {ok, RD, HttpState#http_state{action = disconnect}};
           exit:{noproc, _} when Version =:= 0 ->
               {ok, RD} = cowboy_req:reply(200, text_headers(), Protocol:encode(disconnect), Req),
               {ok, RD, HttpState#http_state{action = disconnect}}
       end.
   
  -handle_polling(Req, Sid, Config, Version) ->
  +handle_polling(Req, Sid, Config, Version, JsonP) ->
       {Method, _} = cowboy_req:method(Req),
       case {socketio_session:find(Sid), Method} of
           {{ok, Pid}, <<"GET">>} ->
               case socketio_session:pull_no_wait(Pid, self()) of
                   {error, noproc} ->
  -                    {shutdown, Req, #http_state{action = error, config = Config, sid = Sid, version = Version}};
  +                    {shutdown, Req, #http_state{action = error, config = Config, sid = Sid, version = Version, jsonp = JsonP}};
                   session_in_use ->
  -                    {shutdown, Req, #http_state{action = error, config = Config, sid = Sid, version = Version}};
  +                    {shutdown, Req, #http_state{action = error, config = Config, sid = Sid, version = Version, jsonp = JsonP}};
                   [] when Version =:= 1 ->
                       case socketio_session:transport(Pid) of
                           websocket ->
  -                            {ok, Req, #http_state{action = data, messages = [nop], config = Config, sid = Sid, pid = Pid, version = Version}};
  +                            {ok, Req, #http_state{action = data, messages = [nop], config = Config, sid = Sid, pid = Pid, version = Version, jsonp = JsonP}};
                           _ ->
  -                            {loop, Req, #http_state{action = heartbeat, config = Config, sid = Sid, pid = Pid, version = Version}, hibernate}
  +                            {loop, Req, #http_state{action = heartbeat, config = Config, sid = Sid, pid = Pid, version = Version, jsonp = JsonP}, hibernate}
                       end;
                   [] when Version =:= 0 ->
                       HeartBeatTimer = erlang:send_after(Config#config.heartbeat, self(), {?MODULE, Pid}),
  -                    {loop, Req, #http_state{action = heartbeat, heartbeat_tref = HeartBeatTimer, config = Config, sid = Sid, pid = Pid, version = Version}, hibernate};
  +                    {loop, Req, #http_state{action = heartbeat, heartbeat_tref = HeartBeatTimer, config = Config, sid = Sid, pid = Pid, version = Version, jsonp = JsonP}, hibernate};
                   Messages ->
  -                    {ok, Req, #http_state{action = data, messages = Messages, config = Config, sid = Sid, pid = Pid, version = Version}}
  +                    {ok, Req, #http_state{action = data, messages = Messages, config = Config, sid = Sid, pid = Pid, version = Version, jsonp = JsonP}}
               end;
           {{ok, Pid}, <<"POST">>} ->
               Protocol = Config#config.protocol,
  -            case cowboy_req:body(Req) of
  -                {ok, Body, Req1} ->
  +            ReqData = case JsonP of
  +                          undefined ->
  +                              case cowboy_req:body(Req) of
  +                                  {ok, Body, Req1} ->
  +                                      {ok, Body, Req1};
  +                                  {error, _} ->
  +                                      error
  +                              end;
  +                          _Num ->
  +                              case cowboy_req:body_qs(Req) of
  +                                  {ok, PostVals, Req1} ->
  +                                      Data = proplists:get_value(<<"d">>, PostVals),
  +                                      {ok, Data, Req1};
  +                                  {error, _} ->
  +                                      error
  +                              end
  +                      end,
  +            case ReqData of
  +                {ok, Data2, Req2} ->
                       DecodeMethod = case Version of
                                   0 -> decode;
                                   1 -> decode_v1
                               end,
  -                    Messages = case catch(Protocol:DecodeMethod(Body)) of
  +                    Messages = case catch(Protocol:DecodeMethod(Data2)) of
                                      {'EXIT', _Reason} ->
                                          [];
                                      {error, _} ->
  
positive.code:     end.
  
  %% Http handlers
  handle(Req, HttpState = #http_state{action = create_session, version = Version, config = #config{
      heartbeat = HeartbeatInterval,
      heartbeat_timeout = HeartbeatTimeout,
      session_timeout = SessionTimeout,
  
negative.code:         {<<"Content-Type">>, <<"application/octet-stream">>}
      ].
  
  javascript_headers(IOCookie) ->
      [
          {<<"Set-Cookie">>, <<"io=", IOCookie/binary>>},
          {<<"Content-Type">>, <<"text/javascript; charset=UTF-8">>},
          {<<"X-XSS-Protection">>, <<"0">>}
      ].
  
  reply_messages(Req, Messages, _Config = #config{protocol = Protocol}, SendNop, 1, undefined) ->
      PacketList = case {SendNop, Messages} of
                   {true, []} ->
                       Protocol:encode_v1([nop]);
                   _ ->
                       Protocol:encode_v1(Messages)
               end,
      PacketListBin = encode_polling_xhr_packets_v1(PacketList),
      {CookieIo, _} = cowboy_req:cookie(<<"io">>, Req),
  
      cowboy_req:reply(200, stream_headers(CookieIo), PacketListBin, Req);
  reply_messages(Req, Messages, _Config = #config{protocol = Protocol}, SendNop, 1, JsonP) ->
      PacketList = case {SendNop, Messages} of
                       {true, []} ->
                           Protocol:encode_v1([nop]);
                       _ ->
                           Protocol:encode_v1(Messages)
                   end,
      PacketListBin = encode_polling_json_packets_v1(PacketList, JsonP),
      {CookieIo, _} = cowboy_req:cookie(<<"io">>, Req),
  
      cowboy_req:reply(200, javascript_headers(CookieIo), PacketListBin, Req);
  reply_messages(Req, Messages, _Config = #config{protocol = Protocol}, SendNop, 0, _JsonP) ->
      Packet = case {SendNop, Messages} of
                   {true, []} ->
                       Protocol:encode([nop]);
  