WordpressTagSearchJSClientNoAuth.html
<html>
<head>
<title> JavaScript web service to Search By Blog by Tag </title>
<!-- importing the wSRequest class from the mooshup script -->
<script language="javascript" src="http://mooshup.com/js/wso2/WSRequest.js"></script>
<!-- here is where we we write the searchTag function -->
<script language="javascript">
function searchTag() {
// getting the tag input value
var tagInput = document.getElementById('tagInput');
var tag = tagInput.value;
// creating the WSRequest
var req = new WSRequest();
if(!req) {
alert("Error in creating the WSRequest, Try again later");
return;
}
// request options
var reqOptions = { useSOAP : true };
var url = "http://ws.dimuthu.org/blog/WordpressTagSearchServiceNoAuth.php";
// providing the options, url, async flag, username, password for the service
req.open(reqOptions, url, true);
// the callback function to execute when the ready state is change
req.onreadystatechange = function() {
if(req.readyState == 4) {
if(req.error == null) {
// here is some use of DOM to retrive values of posts
childNodes = req.responseXML.firstChild.childNodes;
htmlStr = "";
for(i = 0; i < childNodes.length; i ++) {
post = childNodes[i];
// first the title
title = post.childNodes[0].firstChild.nodeValue;
// second the content
content = post.childNodes[1].firstChild.nodeValue;
// third the time
date_str = post.childNodes[2].firstChild.nodeValue;
// filling the html string
htmlStr += "<h2>" + title + " - " + date_str +"</h2>";
htmlStr += "<p>";
htmlStr += content;
htmlStr += "</p>";
htmlStr += "<hr/>";
}
var resultBox = document.getElementById('resultBox');
resultBox.innerHTML = htmlStr;
}
else {
alert("Error Occured, Try again later");
}
// clear the message
document.getElementById('message').innerHTML = "";
}
};
// creating the request xml
var message = "<getPosts><tag>"+ tag +"</tag></getPosts>";
req.send(message);
document.getElementById('message').innerHTML = "Loading..";
}
</script>
</head>
<body>
<div id="tagSearchBox">
<!-- search by tag text -->
Search By Tag <input id="tagInput" type="text" name="tag" value="Mashup"/>
<input type="submit" value="Search" onclick="searchTag()"/>
<strong><span id="message" style="color:red"></span></strong>
</div>
<hr/>
<hr/>
<!-- where we show results -->
<div id="resultBox">
</div>
</body>
</html>