Bug Tracker

Changes between Initial Version and Version 1 of Ticket #8318


Ignore:
Timestamp:
Feb 18, 2011, 12:12:13 PM (9 years ago)
Author:
jitter
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #8318

    • Property Priority changed from undecided to low
    • Property Component changed from unfiled to ajax
  • Ticket #8318 – Description

    initial v1  
    11When I perform cross-domain ajax request:
     2{{{
    23$.ajax({
    3         url:'http://fbtest/cross.php',
    4         crossDomain:true,
    5         data:{
    6                 a:5
    7         },
    8         type:'POST',
    9         dataType:'json',
    10         success:function(data, textStatus, jqXHR) {
    11                 alert(data.name);
    12         }
     4    url:'http://fbtest/cross.php',
     5    crossDomain:true,
     6    data:{
     7        a:5
     8    },
     9    type:'POST',
     10    dataType:'json',
     11    success:function(data, textStatus, jqXHR) {
     12        alert(data.name);
     13    }
    1314});
     15}}}
    1416Script that sends response is:
     17{{{
    1518<?php
    1619header('Access-Control-Allow-Origin: *');
    1720echo file_get_contents('cross.json');
    18 
     21}}}
    1922cross.json is:
     23{{{
    2024{
    2125    "name": "konst"
    2226}
    23 
     27}}}
    2428When I do GET request, everything is fine. When I do POST, request is not sent and in chrome it says:
     29{{{
    2530XMLHttpRequest cannot load http://fbtest/cross.php. Request header field x-requested-with is not allowed by Access-Control-Allow-Headers.
     31}}}
    2632
    2733I've tracked down the code and found these lines in development version of jquery 1.5:
     34{{{
    2835// Requested-With header
    2936// Not set for crossDomain requests with no content
     
    3340        headers[ "x-requested-with" ] = "XMLHttpRequest";
    3441}
    35 
     42}}}
    3643So you've got it right - you should NOT set x-requested-with header for cross-domain request. However you do. When I comment out this logic, it works fine. I think there is something wrong with checks you do.