2013-08-06 48 views
0

我有一個SharePoint列表,我使用Lists.asmx帶來的信息使用AJAX,但沒有什麼東西從回來服務器....我在做什麼錯了?我正在做一個Ajax調用Lists.asmx,我沒有得到任何回

這是我的代碼:

var Currentlocurl; 

$(document).ready(function() { 
    $(".vincLista").bind("click", function(){ 
     L_Menu_BaseUrl = "empaquetamiento" 
     if (window.location.port != null || window.location.port != '') { 
      Currentlocurl = window.location.protocol + "//" + window.location.hostname + ":" + window.location.port + L_Menu_BaseUrl; 
      } 
     else { 
      Currentlocurl = window.location.protocol + "//" + window.location.hostname + L_Menu_BaseUrl; 
      } 

     var listurl = Currentlocurl + "/_vti_bin/lists.asmx"; 
     var listname = "Empaquetamiento"; 
     var query = "<Where>" + 
      "<And>" + 
       "<Eq>" + 
        "<FieldRef Name='Plan' />" + 
        "<Value Type='Choice'>" + $(this).data("plan") + "</Value>" + 
       "</Eq>" + 
       "<Eq>" + 
        "<FieldRef Name='Operacion' />" + 
        "<Value Type='Choice'>" + $(this).data("operacion") + "</Value>" + 
       "</Eq>" + 
      "</And>" + 
      "</Where>"; 

     var soap = "<?xml version=\"1.0\" encoding=\"utf-8\"?> \ 
      <soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \ 
      <soapenv:Body> \ 
      <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \ 
      <listName>" + listname + "</listName><query><Query>" + query + "</Query></query> \ 
      <viewFields><ViewFields>\ 
       <FieldRef Name='id' />\ 
       <FieldRef Name='Nombre' />\ 
       <FieldRef Name='Descripcion' />\ 
       <FieldRef Name='Codigo SAP' />\ 
       <FieldRef Name='Proforma' />\ 
       <FieldRef Name='Imagen grande' />\ 
       <FieldRef Name='Imagen pequeña' />\ 
      </ViewFields></viewFields> \ 
      </GetListItems> \ 
      </soapenv:Body></soapenv:Envelope>"; 

     $.ajax({ 
      url: listurl, 
      beforeSend: function (xhr) { 
         xhr.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/GetListItems"); 
        }, 
      type: "POST", 
      dataType: "xml", 
      data: soap, 
      complete: function (xData, status) { 
       $(xData.responseXML).find("z\\:row").each(function() { 
        var infoDiv = $('<div/>', {class: "pieza", text: $(this).attr("ows_Nombre") + $(this).attr("ows_Descripcion")}); 
        $("#info").append(infoDiv); 
        }); 
       }, 
      contentType: "text/xml; charset=utf-8" 
     }); 
    }); 
}); 

,這是我的html:

<!DOCTYPE html> 
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7",lang=''><![endif]--> 
<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8",lang=''><![endif]--> 
<!--[if IE 8]><html class="no-js lt-ie9",lang=''><![endif]--> 
<!--[if gt IE 8]><!--> 
<html> 
<!--<![endif]--> 
<head> 
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> 
    <meta charset="utf-8" /> 
    <title>Empaquetamiento</title /> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 
    <meta name="description" content="" /> 
    <meta name="author" content="" /> 

    <!-- Libraries--> 
    <!-- Javascript extra--> 
    <!--[if lt IE 9]> 
    <script src="/empaquetamiento/JS/html5shiv.js"></script> 
    <script src="/empaquetamiento/JS/html5shiv-printshiv.js"></script><![endif]--> 
    <!-- Support for IE6-8 of HTML5 elements--> 

    <script type="text/javascript" src="javascript/modernizr.min.js"></script> 

    <!-- Css Styles--> 
    <link rel="stylesheet" href="stylesheets/empaquetamiento.css"/> 

</head> 
<body> 
    <button class="vincLista" data-plan="Plan1" data-operacion="inicio" >Traer info</button> 
    <button class="vincLista" data-plan="Plan1" data-operacion="diseño" >Traer info</button> 
    <button class="vincLista" data-plan="Plan2" data-operacion="inicio" >Traer info</button> 
    <button class="vincLista" data-plan="Plan2" data-operacion="diseño" >Traer info</button> 
    <div id="info" ></div> 

    <button class="vincPieza" data-id="1" >Traer info</button> 
    <div id="pieza" ></div> 

    <script type="text/javascript" src="javascript/jquery-1.10.2.min.js"></script> 
    <script type="text/javascript" src="javascript/empaquetamiento.js"></script> 
</body> 
</html> 

AJAX的方法被調用,但我從來沒有從服務器得到一個答案,甚至不是一個錯誤。

回答

0

您是否嘗試過使用FireBug或Chrome的內置開發者工具調試您的服務器調用?您可以使用這些工具查看服務器調用和服務器響應。

+0

嗨,是由於我已經發現了一些問題,我有,首先L_Menu_BaseUrl =「empaquetamiento」應該是L_Menu_BaseUrl =「/ empaquetamiento的「因爲它工作正常。 –

1

我發現問題出在哪裏,首先我在我的列表欄中使用了「operación」和「descripción」這樣的詞彙,這個詞讓我有些麻煩,而且我的菜單基礎網址錯了。

下面是更正後的代碼,一些重構後:

var Currentlocurl; 

$(document).ready(function() { 

    L_Menu_BaseUrl = "/empaquetamiento" 
    if (window.location.port != null || window.location.port != '') { 
     Currentlocurl = window.location.protocol + "//" + window.location.hostname + ":" + window.location.port + L_Menu_BaseUrl; 
    } 
    else { 
     Currentlocurl = window.location.protocol + "//" + window.location.hostname + L_Menu_BaseUrl; 
    } 

    var listurl = Currentlocurl + "/_vti_bin/lists.asmx"; 
    var listname = "Empaquetamiento"; 

    $(".vincLista").bind("click", function(){ 
     var query = "<Where>" + 
      "<And>" + 
       "<Eq>" + 
        "<FieldRef Name='Plan' />" + 
        "<Value Type='Choice'>" + $(this).data("plan") + "</Value>" + 
       "</Eq>" + 
       "<Eq>" + 
        "<FieldRef Name='Operacion' />" + 
        "<Value Type='Choice'>" + $(this).data("operacion") + "</Value>" + 
       "</Eq>" + 
      "</And>" + 
      "</Where>"; 

     var viewFields = "<ViewFields>\ 
       <FieldRef Name='Title' />\ 
       <FieldRef Name='Nombre' />\ 
       <FieldRef Name='Imagen' />\ 
      </ViewFields>"; 

     var soap = "<?xml version=\"1.0\" encoding=\"utf-8\"?> \ 
      <soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \ 
      <soapenv:Body> \ 
      <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \ 
      <listName>" + listname + "</listName><query><Query>" + query + "</Query></query> \ 
      <viewFields>" + viewFields + "</viewFields> \ 
      </GetListItems> \ 
      </soapenv:Body></soapenv:Envelope>"; 

     $.ajax({ 
      url: listurl, 
      beforeSend: function (xhr) { 
       xhr.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/GetListItems"); 
      }, 
      type: "POST", 
      dataType: "xml", 
      data: soap, 
      complete: function (xData, status) { 
       $(xData.responseXML).find("z\\:row, row").each(function() { 
        var infoDiv = $('<div/>', {class: "pieza", text: $(this).attr("ows_Nombre") + " - " + $(this).attr("ows_Imagen")}); 
        $("#info").find("#pieza").delete; 
        $("#info").append(infoDiv); 
       }); 
      }, 
      error: function(xhr, ajaxOptions, thrownError) { 
       alert(thrownError); 
      }, 
      contentType: "text/xml; charset=utf-8" 
     }); 
    }); 
}); 
相關問題