SharePoint 2010 -- search.asmx from Javascript using xmlHttpRequest - Cannot get results

Hello my dear developers,

I have this big issue and, after many trials, I m not able to find an answer yet !

Issue is about calling SharePoint 2010 search.asmx service from javascript code (using xmlHttpRequest and response)

Two thousand billion dollars for you, if you make this code working   : ///

After I click on the link, no results are shown in the alert window. Please help me !  

______________________________________________________________

<script>
function RetrieveSearchData()

{

    //get the request object

    var requestObject = new XMLHttpRequest();

    //Initializes request and specifies the method, URL, and other information for the request.

    requestObject.open("POST", "http://mysitecollection.domain:77/_vti_bin/search.asmx", false);

    //set request header

    requestObject.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

    var packet = "<?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><QueryEx xmlns="<queryxml><querypacket">http://microsoft.com/webservices/OfficeServer/QueryService"><queryXml><QueryPacket</querypacket"></queryxml> Revision=\"1000\"><Query><Context><QueryText type=\"STRING\">(contentsource:\"MYCONTENTSOURCE\")</QueryText></Context><SupportedFormats Format=\"urn:Microsoft.Search.Response.Document.Document\"/><ResultProvider>FASTSearch</ResultProvider><Range><StartAt>1</StartAt><Count>20</Count></Range><EnableStemming>true</EnableStemming><EnableSpellCheck>Suggest</EnableSpellCheck><IncludeSpecialTermsResults>true</IncludeSpecialTermsResults><IncludeRelevantResults>true</IncludeRelevantResults><ImplicitAndBehavior>true</ImplicitAndBehavior><TrimDuplicates>true</TrimDuplicates><Properties><Property name=\"IsDocument\"/><Property name=\"Url\" /><Property name=\"FileExtension\"/></Properties></Query></QueryPacket></queryXml></QueryEx></soap:Body></soap:Envelope>";


 //Sends an HTTP request to the server and receives a response

 requestObject.send(packet);

 //process responseXML
 
 alert(requestObject.responseText);

}

</script>

<a onclick="RetrieveSearchData()" href="#">SEARCH</a>

_____________________________________________________________

My best regards !!

Gae

January 17th, 2014 9:57pm

Have you tried switching to JQuery and using Fiddler to monitor the traffic?
Free Windows Admin Tool Kit Click here and download it now
January 18th, 2014 12:14pm

Thank you Chris for your answer ! 

I've not tried it yet, but before doing that I would like to know if you can find some syntax errors, for example in "var packet" string definition.

Many many thanks,

Gae

January 19th, 2014 5:41am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics