0

When I call the following code locally using IE it works, but when using Firefox or Chrome I get a "ParseError". The code works fine in IE, and retrieves all the People in my Sharepoint directory that match the search criteria, but when I call it from Firefoxs it fails....

    <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>&lt;QueryPacket xmlns='urn:Microsoft.Search.Query'&gt;&lt;Query&gt;&lt;SupportedFormats&gt;&lt;Format revision='1'&gt;urn:Microsoft.Search.Response.Document:Document&lt;/Format&gt;&lt;/SupportedFormats&gt;&lt;Context&gt;&lt;QueryText language='en-US' type='MSSQLFT'&gt;" + userSearchQueryString + "&lt;/QueryText&gt;&lt;/Context&gt;&lt;/Query&gt;&lt;/QueryPacket&gt;</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(/&lt;/g, "<").replace(/&gt;/g, ">");
        }

        $(document).ready(function() {
            $("a#submit").click(function() {
            Search();
    });
}); 
    </script> 
Dante López
  • 213
  • 3
  • 10
  • What XML does the ajax call return? – Matt Ball Dec 16 '11 at 21:12
  • Off the top of my head, I would guess this: `xhr.setRequestHeader("SOAPAction", "urn:Microsoft.Search/Query");`. But I am not sure. – Andrew Jackman Dec 16 '11 at 21:14
  • This may be something you already know, but you can see more information on what is going wrong when you use FireBug (http://getfirebug.com/). Under the "Net" tab and "XHR", you can see the AJAX post and response, which is what I believe MДΓΓ БДLL was asking. – JNadal Dec 16 '11 at 22:11
  • Looking at the network information, I can see that I'm getting a "401 Unauthorized" Error.... But this only happens in Chrome and FF, not IE..... – Dante López Dec 17 '11 at 00:13

1 Answers1

0

Maybe it helps. I had the same problem.

For cross-browser-compatility you need to use:

$(xData.responseXML).text()

For the url you should use:

url: "/_vti_bin/search.asmx",

because cross domain Ajax call is not possible.

Littm
  • 4,923
  • 4
  • 30
  • 38
thorge
  • 1