当我使用IE在本地调用以下代码时,它可以工作,但是当使用Firefox或Chrome时,我得到一个“ParseError”。 代码在IE中工作正常,并检索我的Sharepoint目录中符合搜索条件的所有People,但是当我从Firefox调用它时它失败了....
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
function Search() {
var userSearchQueryString =
"SELECT Size, Rank, Path, Title, UserProfile_GUID, PreferredName, AccountName, UserName FROM scope() WHERE FREETEXT(DefaultProperties, '" + $("#search").val() + "') AND ( (\"SCOPE\" = 'People') )"
var soapEnv =
"<?xml version=\"1.0\" encoding=\"utf-8\"?> \
<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> \
<Query xmlns=\"urn:Microsoft.Search\"> \
<queryXml><QueryPacket xmlns='urn:Microsoft.Search.Query'><Query><SupportedFormats><Format revision='1'>urn:Microsoft.Search.Response.Document:Document</Format></SupportedFormats><Context><QueryText language='en-US' type='MSSQLFT'>" + userSearchQueryString + "</QueryText></Context></Query></QueryPacket></queryXml> \
</Query> \
</soap:Body> \
</soap:Envelope>"
$.ajax({
url: "http://sharepoint.myserver.com/_vti_bin/search.asmx",
beforeSend: function(xhr) {
xhr.setRequestHeader("SOAPAction",
"urn:Microsoft.Search/Query");
},
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=utf-8"
});
}
function processResult(xData, status) {
var title;
var username;
var guid;
var user;
$('Property Name', xData.responseXML.text).each(function() {
var $this = $(this);
if ($this.text() === "TITLE") {
user = '';
title = $this.nextAll("Value").text();
user = title;
}
if ($this.text() === "USERPROFILE_GUID") {
guid = $this.nextAll("Value").text();
user = user + ' - ' + guid;
}
if ($this.text() === "USERNAME") {
username = $this.nextAll("Value").text();
user = user + ' - ' + username;
alert(user);
}
});
//var xml = responseXMLxml.replace(/</g, "<").replace(/>/g, ">");
}
$(document).ready(function() {
$("a#submit").click(function() {
Search();
});
});
</script>
答案 0 :(得分:0)
查看此答案:JQuery - $.ajax ContentType Problem in Firefox
用户Karmic Coder解释了可能导致您出现问题的情况。
答案 1 :(得分:0)
也许有帮助。我遇到了同样的问题。
对于跨浏览器兼容性,您需要使用:
$(xData.responseXML).text()
对于您应该使用的网址:
url: "/_vti_bin/search.asmx",
因为无法进行跨域Ajax调用。