通过$ .ajax将多个变量传递给beforeSend函数

时间:2011-06-12 20:28:57

标签: jquery ajax

我有以下Ajax调用:

function ajaxCall(soap, url){
    // Post SOAP request.
    $.ajax({
        type: "POST",
        url: url,
        contentType: "text/xml",
        data: soap,
        dataType: "xml",
        processData: false,
        beforeSend: passToProxy(url),
        success: onSuccess,
        error: function(){
            getRandom();
        }
    });
}

function passToProxy(xhr,url1) {
    alert(url1);
     // Pass the target URL onto the proxy.
     xhr.setRequestHeader("SOAPTarget","http://localhost:8088/mockSDClientSOAPBinding");
     // Pass the action onto the proxy.
     xhr.setRequestHeader("SOAPAction","invoke");
}

我希望能够将url变量传递给passToProxy函数(想要用变量url替换“http:// localhost:8088 / mockSDClientSOAPBinding”),但我认为这里没有正确的想法。 passToProxy中的警报弹出“未定义”。我做错了什么?

1 个答案:

答案 0 :(得分:6)

也许你想要:

beforeSend: function(xhr){ passToProxy(xhr, url); }