我試圖訪問另一個域中的web服務,它什麼都沒有返回。後來我發現這是一個跨域訪問的問題。Jquery跨域問題
我在網上搜索,有這麼多的文章,但沒有人可以像我這樣的新手可讀。 :(
有人可以幫助我如何訪問web服務?
下面是我的代碼。
//variables for Add Contacts
var addAccountServiceUrl = 'http://crm.eyepax.net/organization.asmx?op=WriteOrg'; // 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="[email protected]";
var Flag=1;
var LicenceOrganazationID=1;
var sErr;
function addContact()
{
//this is to be commented soon!
alert("function called");
//update the webservice soapmesg
var soapMessage =
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> \
<soap:Body> \
<WriteOrg xmlns="http://eyepax.crm.com/Organization"> \
<OrganizationID>'+OrganizationID+'</OrganizationID> \
<ParentID>'+ParentID+'</ParentID> \
<AccountManagerID>'+AccountManagerID+'</AccountManagerID> \
<OrganizationName>'+OrganizationName+'</OrganizationName> \
<IncorporationNo>'+IncorporationNo+'</IncorporationNo> \
<PostAddress>'+PostAddress+'</PostAddress> \
<CountryID>'+CountryID+'</CountryID> \
<VisitAddress>'+VisitAddress+'</VisitAddress> \
<VisitCountryID>'+VisitCountryID+'</VisitCountryID> \
<VisitSwithboard>'+VisitSwithboard+'</VisitSwithboard> \
<VisitFax>'+VisitFax+'</VisitFax> \
<Www>'+Www+'</Www> \
<Active>'+Active+'</Active> \
<RegBy>'+RegBy+'</RegBy> \
<ConfigurationCode>'+ConfigurationCode+'</ConfigurationCode> \
<Flag>'+Flag+'</Flag> \
<LicenceOrganazationID>'+LicenceOrganazationID+'</LicenceOrganazationID> \
</WriteOrg> \
</soap:Body> \
</soap:Envelope>';
$.ajax({
url: addAccountServiceUrl,
type: "POST",
dataType: "xml",
data: soapMessage,
success: endAddContact,
error: function(jqXHR, textStatus, errorThrown) {alert("failure"); console.log(textStatus);console.log(errorThrown);},
contentType: "text/xml; charset=\"utf-8\""
});
return false;
}
function endAddContact(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());
}
你能夠做到這一點嗎? – 2013-01-02 12:28:07