jquery怎么设置请求消息头

$.ajax({
  beforeSend :function(xhr){
   xhr.setRequestHeader('消息头','值');//设置消息头
 }
}); 


function makeRequest() {
    alert("inside makeRequest()");
    var settings = {
        type: "GET",
        url:URL+"?"+REQUEST,
        dataType:"xml",
        error: function(XHR,textStatus,errorThrown) {
            alert ("XHR="+XHR+"\ntextStatus="+textStatus+"\nerrorThrown=" + errorThrown);
        },
        success: function(data,textStatus) {
            $("body").append(data);
        },
        headers: {
            "Access-Control-Allow-Origin":"http://example.edu",
            "Access-Control-Allow-Headers":"X-Requested-With"
        }
    };
    $.ajax(settings);
}

PHP判断是否是Ajax请求

isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest';


你可能感兴趣的:(PHP,Yii,jquery)