Question : making multiple url calls on the same page in javascript

The easiest way to describe this is by example. If you look below I am try to implement the same piece of javascript code twice, but one uses a different search term. On my page though only the second one works properly:

http://www.glowfishtw.com/landing_pages/blog_search_example.html

How can I get both to run properly together?

Thanks

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
<html>
 <head>
     <script language="javascript">
         document.domain="construction.com";
     </script>
     <script type="text/javascript" src="http://sitelife.construction.com/ver1.0/Direct/DirectProxy"></script>

 </head>
 <body>

   <script language="javascript">
         document.domain="construction.com";
     </script>
     <script type="text/javascript" src="http://sitelife.construction.com/ver1.0/Direct/DirectProxy"></script>
 </head>
 <body>
   <script language="JavaScript">
       var requestBatch = new RequestBatch();
       var serverUrl = "http://sitelife.construction.com/ver1.0/Direct/Process";
   
       var searchType = "BlogPost";  // others are Comment, ForumPost, Gallery, Photo, Video
       
       // var searchString = "Title:Pennsylvania";  // To search only the title for Penn
       var searchString = "Pennsylvania";
              
       requestBatch.AddToRequest(new SearchAction(searchType, searchString, 10, 1));
       requestBatch.BeginRequest(serverUrl, clientCallBack);

       function clientCallBack(responseBatch) {
         // console.dir(responseBatch);  // -- use this in Firefox (only) to show the responseBatch object in the console to see what data is available.
         
         var searchResults = responseBatch.Responses[0].SearchResult.SearchResults;
         var htmlString = "<h2>" + searchType + " Search Results " + "for " + searchString + ":</h2><br>";

	 if (searchType == "BlogPost") // only showing an example of BlogPost for now
	 {
           for (var i = 0; i < searchResults.length; i++)
             htmlString += "<a href=\"" + searchResults[i].Url + "\">" + searchResults[i].PostTitle + "</a> by: <a href=\"" + searchResults[i].PostAuthor.PersonaUrl + "\">" + searchResults[i].PostAuthor.DisplayName + "</a> on " + searchResults[i].PostDate + "<br>";
         }

	 document.getElementById("output_div").innerHTML = htmlString;
       }

   </script>
   <div id="output_div"></div>
  
  
   <script language="JavaScript">
       var requestBatch = new RequestBatch();
       var serverUrl = "http://sitelife.construction.com/ver1.0/Direct/Process";
   
       var searchType = "ForumPost";  // others are Comment, ForumPost, Gallery, Photo, Video
       
       // var searchString = "Title:Pennsylvania";  // To search only the title for Penn
       var searchString = "Pennsylvania";
              
       requestBatch.AddToRequest(new SearchAction(searchType, searchString, 10, 1));
       requestBatch.BeginRequest(serverUrl, clientCallBack);

       function clientCallBack(responseBatch) {
         // console.dir(responseBatch);  // -- use this in Firefox (only) to show the responseBatch object in the console to see what data is available.
         
         var searchResults2 = responseBatch.Responses[0].SearchResult.SearchResults;
         var htmlString2 = "<h2>" + searchType + " Search Results " + "for " + searchString + ":</h2><br>";

	 if (searchType == "ForumPost") // only showing an example of BlogPost for now
	 {
           for (var i = 0; i < 10; i++)
             htmlString2 += "<a href=\"" + searchResults2[i].PostUrl + "\">" + searchResults2[i].PostTitle + "</a> by: <a href=\"" + searchResults2[i].LiteUser.PersonaUrl + "\">" + searchResults2[i].LiteUser.DisplayName + "</a> on " + searchResults2[i].LastUpdated + "<br>";
         }

	 document.getElementById("output_div2").innerHTML = htmlString2;
       }

   </script>
   <div id="output_div2"></div>
   

   
 </body>
</html>

Answer : making multiple url calls on the same page in javascript

I'm not sure but the comment on lines 21 and 52 indicates the following are valid search terms:
Comment, ForumPost, Gallery, Photo, Video

In your second script you are using ForumPost which is valid, but in the first one you are using BlogPost which is not indicated as being vaild.  I'm basing this purly on the comment on lines 21 and 52.
Random Solutions  
 
programming4us programming4us