Calling Search Web Service in Javascript => Bad Request


  • Hi all,


    I'm tryng to call the Search Web Service of Sharepoint from a Javascript function. Here is the code I'm using:

    function Search()


    var qs = new Querystring();

    var keywordString = qs.get("keywordString");

    var quo;

    quo = String.fromCharCode(34);

    var queryXml = "<QueryPacket xmlns="+quo+"urn:Microsoft.Search.Query"+quo+">";

    queryXml += "<Query domain="+quo+"QDomain"+quo+">";

    queryXml += "<SupportedFormats>";

    queryXml += "<Format revision="+quo+"1"+quo+">urn:Microsoft.Search.Response.Document:Document</Format>";

    queryXml += "</SupportedFormats>";

    queryXml += "<Context>";

    queryXml += "<QueryText language="+quo+"fr-FR"+quo+" type="+quo+"STRING"+quo+">" + keywordString + "</QueryText>";

    queryXml += "</Context>";

    queryXml += "<Range><StartAt>1</StartAt><Count>25</Count></Range>";

    queryXml += "</Query>";

    queryXml += "</QueryPacket>";

    var strEnvelope;

    strEnvelope = "<?xml version="+quo+"1.0"+quo+" encoding="+quo+"utf-8"+quo+"?>";

    strEnvelope += "<soap:Envelope xmlns:xsi="+quo+""+quo+" xmlns:xsd="+quo+""+quo+" xmlns:soap="+quo+""+quo+">";

    strEnvelope += "<soap:Body>";

    strEnvelope += "<QueryEx xmlns="+quo+""+quo+">";

    strEnvelope += "<queryXml>"+queryXml+"</queryXml>";

    strEnvelope += "</QueryEx>";

    strEnvelope += "</soap:Body>";

    strEnvelope += "</soap:Envelope>";

    PrepareXmlHttp();"POST", "http://sharepointemea/sites/vistapoint/_vti_bin/search.asmx?op=QueryEx", true);

    xmlHttp.onreadystatechange = function()


    if (xmlHttp.readyState == 4)



    var szResponse = xmlHttp.responseText;

    var xmlDoc = new ActiveXObject("Microsoft.XMLDom");

    xmlDoc.async = "false";




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


    xmlHttp.setRequestHeader("Content-Length", strEnvelope.length);





    But this part of the code: 

    var szResponse = xmlHttp.responseText;

     always displays a "Bad Request" message. I've searched over Internet but found nothing and my code seems to be fine.


    Anone got an idea ?






    Monday, March 12, 2007 10:46 AM

All replies

  • Nobody get an idea ? :(
    Tuesday, March 13, 2007 8:54 AM
  • I too am trying to use the search web service from javascript, my code is below:


    function sendSearchSOAP(terms){

    var searchQuery =

    '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlnsTongue Tiedoap="'">"><soap:Body>' +

    '<QueryPacket xmlns="urn:Microsoft.Search.Query"><Query><Context><QueryText>' + terms + '</QueryText></Context></Query></QueryPacket>'+




    // code for Mozilla, etc.
    if (window.XMLHttpRequest)
      xmlhttp=new XMLHttpRequest()
    // code for IE
    else if (window.ActiveXObject)
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp!=null)
      xmlhttp.setRequestHeader('SOAPAction', 'urn:Microsoft.Search/Query');
      xmlhttp.setRequestHeader("Content-Type", "text/xml");



    I am getting a valid SOAP envelope back from the service with an Internal Server Error, is this what you are getting?


    I am going mental trying to find out what is wrong. I have managed to return a list of subWebs etcetera with other servces but do not seem to be able to get the search service to work at all.

    Thursday, May 10, 2007 2:44 PM
  • Hi Thomas,


    Did you find a solution to this problem. I am having the same problem.




    Thomas Nielsen

    Tuesday, December 11, 2007 11:05 AM
  • me 2 getting same error.. anybody found the solution?
    Monday, November 18, 2013 1:18 PM