使用jQuery UI Modal Form的AJAX responseXML为空

时间:2013-07-26 20:39:13

标签: javascript jquery-ui jquery

我有一个对SharePoint Web服务的jQuery ajax调用,我用它将“搜索”结果附加到表中。只有一个简单的html表一切正常并且结果被添加,但是当我尝试将结果添加到jQuery UI模式形式时,调用返回0结果并且responseXML看起来为null(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);
}

1 个答案:

答案 0 :(得分:0)

问题是responseXML的jQuery 1.9.1错误。正如我在使用1.8.3版本的评论中提到的那样“解决”了这个问题。您可以在jQuery bug trackerthis blog上阅读更多相关信息。