1

我有一个对 SharePoint Web 服务的 jQuery ajax 调用,用于将“搜索”结果附加到表中。只有一个简单的 html 表,一切正常并添加了结果,但是当我尝试将结果添加到 jQuery UI 模态表单时,调用返回 0 结果并且 responseXML 似乎为空(responseText 返回预期的字符串)。我希望我只是错过了一些简单的事情。欢迎任何想法。

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 UI):

$(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);
}
4

1 回答 1

0

问题是带有 responseXML 的 jQuery 1.9.1 错误。正如我在评论中提到的,使用 1.8.3 版“解决”了这个问题。你可以在jQuery bug tracker这个博客上阅读更多信息。

于 2013-09-19T17:45:50.573 回答