1
我有一個jQuery ajax調用SharePoint Web服務,我用來追加「搜索」結果到表。只有一個簡單的html表格一切正常,並且結果被添加,但是當我嘗試將結果添加到jQuery UI模式窗體中時,調用返回0結果並且responseXML顯示爲null(responseText返回期望的字符串)。我希望我錯過了一些簡單的事情。任何想法都歡迎。AJAX響應XML空jQuery UI模式形式
HTML:
<p id="myDescrip">This is a test page for CAML Web Service Queries</p>
<button id="SearchItems">Search for Transcripts</button>
<div id="dialog-results" title="Search Results">
<p id="myResults">Your search results are:</p>
<table id="SearchData" class="myTable">
<tr>
<th>Last Name</th>
<th>First Name</th>
<th>Transcripts School</th>
<th>Date Received</th>
</tr>
</table>
</div>
的JavaScript(jQuery的/ jQuery用戶界面):
$(function() {
// Button control
$("#SearchItems")
.button()
.click(function() {
SearchTranscripts();
});
// Dialog control
$("#dialog-results").dialog({
autoOpen: false,
resizable: false,
height:300,
width:500,
modal: true,
buttons: {
Cancel: function() {
$(this).dialog("close");
}
}
});
});
// Query the SharePoint list
function SearchTranscripts() {
var soapEnv = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>"
soapEnv += "<soapenv:Body>"
soapEnv += "<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>"
soapEnv += "<listName>Transcripts Log</listName>"
soapEnv += "<query><Query><Where><Or><Contains><FieldRef Name='Title' /><Value Type='Text'>Smith</Value></Contains>"
soapEnv += "<Contains><FieldRef Name='First_Name' /><Value Type='Text'>Smith</Value></Contains></Or></Where>"
soapEnv += "<OrderBy><FieldRef Name='Title' Ascending='True' /></OrderBy></Query></query>"
soapEnv += "<viewFields>"
soapEnv += "</viewFields>"
soapEnv += "<rowLimit>5000</rowLimit>"
soapEnv += "</GetListItems>"
soapEnv += "</soapenv:Body>"
soapEnv += "</soapenv:Envelope>";
$.ajax({
url: "/xxx/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
error: errorResult,
contentType: "text/xml; charset=\"utf-8\""
});
}
// Add items to the list
function processResult(xData) {
var myFname = "";
var myLname = "";
var mySchool = "";
var myDate = "";
var myID = "";
var itemUrl = "/xxx/DispForm.aspx?ID=";
var nr = 0;
$(xData.responseXML).find("z\\:row").each(function() {
myFname = $(this).attr("ows_First_Name");
myLname = $(this).attr("ows_Title");
mySchool = $(this).attr("ows_College");
var tmpd = $(this).attr("ows_Date_Received");
// Check for invalid dates
if(!tmpd){
myDate = "n/a";
} else {
myDate = tmpd.substring(5, 7).replace("0","") + "/"
myDate += tmpd.substring(8, 10).replace("0","") + "/"
myDate += tmpd.substring(0, 4);
}
myID = $(this).attr("ows_ID");
// Create the new row
var AddRow = "<tr><td><a href='" + itemUrl + myID + "'>" + myLname + "</a></td>"
AddRow += "<td>" + myFname + "</td>"
AddRow += "<td>" + mySchool + "</td>"
AddRow += "<td>" + myDate + "</td></tr>"
$("#SearchData").append(AddRow);
nr += 1;
});
$("#myResults").html($("#myResults").html() + " " + nr)
$("#dialog-results").dialog("open");
}
// Show Error
function errorResult(xData) {
alert(xData.responseText);
}
我還沒有能夠得到這個工作,所以我不得不默認爲一個普通的HTML表格解決方案(這工作正常,只是不像花式)。如果有人有任何猜測,我願意嘗試。 –
爲了防止任何人絆倒這一點,我找出了什麼是錯的。這是jQuery的版本。我的AJAX調用並不滿意1.9.1,所以我只是將參考改爲1.8.3,一切正常。如果我用1.9.1解決這個問題,我會在這裏發佈。 –