jQuery: The Write Less, Do More JavaScript Library

Changeset 4439

Show
Ignore:
Timestamp:
01/14/08 18:19:28 (7 months ago)
Author:
jeresig
Message:

Just added support for Accept headers in Ajax requests - defaults to the correct header depending on the type of request that's being performmed. (Bug #1986)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/src/ajax.js

    r4359 r4439  
    147147        data: null, 
    148148        username: null, 
    149         password: null 
     149        password: null, 
     150        accepts: { 
     151            xml: "application/xml, text/xml", 
     152            html: "text/html", 
     153            script: "text/javascript, application/javascript", 
     154            json: "application/json, text/javascript", 
     155            text: "text/plain", 
     156            default: "*/*" 
     157        } 
    150158    }, 
    151159     
     
    276284            // Set header so the called script knows that it's an XMLHttpRequest 
    277285            xml.setRequestHeader("X-Requested-With", "XMLHttpRequest"); 
     286 
     287            // Set the Accepts header for the server, depending on the dataType 
     288            xml.setRequestHeader("Accept", s.dataType && s.accepts[ s.dataType ] ? 
     289                s.accepts[ s.dataType ] + ", */*" : 
     290                s.accepts.default ); 
    278291        } catch(e){} 
    279292