使用PHP代理进行跨域访问

我正在通过jQuery访问XML(.net)Web服务,并且由于跨域访问限制,我受到限制。 我使用Simple PHP代理并调用webservice。 作为一个新手webdev真的很头疼。

我正在做一个有趣的回应,如下所示。

{"status":{"http_code":500},"contents":"soap:ReceiverServer was unable to process request. ---> Root element is missing."} 

这是我的JavaScript

 var proxy = 'proxy.php'; //http://crm.eyepax.net/contact.asmx?op=LogIn //variables for Add Contacts var addAccountServiceUrl = proxy+'?url='+serviceURL'; // Preferably write this out from server side var OrganizationID=123; var ParentID=123 ; var AccountManagerID="123"; var OrganizationName="Testapple"; var IncorporationNo="23"; var PostAddress="asdfklj asldfj"; var CountryID="LK"; var VisitAddress="asldkf asldkf asldfas dfasdf"; var VisitCountryID="LK"; var VisitSwithboard="242344"; var VisitFax="234234"; var Www="http://www.eyepax.com"; var Active=true; var RegBy=345345345345; var ConfigurationCode="28BC9CC3@BFEBFBFF0001067A"; var Flag=1; var LicenceOrganazationID=1; var sErr; var userName="test123"; var password="Eyepax321"; var flag="2"; function addContact() { //this is to be commented soon! //alert("function called"); //update the webservice soapmesg var soapMessage = ' \  \  \ '+userName+' \ '+password+' \ '+ConfigurationCode+' \ '+flag+' \  \  \ '; $.ajax({ beforeSend: function(jqXHR, settings) { //var xhr = new CrossXHR(); //jqXHR = xhr; }, url: addAccountServiceUrl, type: "POST", dataType: "xml", data: soapMessage, crossDomain: true, success: endAddAccount, error: function(jqXHR, textStatus, errorThrown) { alert("failure"); console.log(textStatus); console.log(errorThrown);}, contentType: "text/xml; charset=\"utf-8\"" }); return false; } function endAddAccount(xmlHttpRequest, status) { console.log(xmlHttpRequest); console.log(status); alert("webservice called!"); $(xmlHttpRequest.responseXML) .find('WriteOrgResponse') .each(function() { var orgres = $(this).find('WriteOrgResult').text(); var error = $(this).find('vstrError').text(); alert(orgres +' -'+ error); }); var a = $(xmlHttpRequest.responseXML).find('WriteOrgResult'); var b = $(xmlHttpRequest.responseXML).find('vstrError'); console.log("a"+a.text()); console.log("b"+b.text()); } //function for field validation $("#add_account_page").live('pageinit', function(event) { //alert("Add Test"); var account_name_val; $("#submit").click(function(){ account_name_val = $("#account_name").val(); // this function is used to see whether mandatory field Account Name is available if(account_name_val==""){ alert("Please fill Account Name"); $("#account_name").focus(); } else{ //calling webservice addContact(); } }); }); 

PHP代理源

我能够通过PHP代理发送reqeust并获得结果。