HTML and CSS   XSLT   JavaScript   Images   Soft   Etc  
Andrey Shitov

JavaScript client for Typograf 29 November 2005


Task: Develope a  JavaScript web service client.

Some time ago I created a web service allowing you to use Typograf outside the website. Atteched to it were several examples in different languages. Later, I received replies asking to another one—in JavaScript.

Technical
digression

If I had to provide keywords for the page, I would use these: web service, XML web service, SOAP, WSDL.


Let me make a reservation that in practice, as far as I know, there’s little need for JavaScript client.

It boils down to creating an XML in accordance with SOAP and sending it to server.

var xmlRequest = 
	'<?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>' +
			'<ProcessText xmlns="http://typograf.artlebedev.ru/webservices/">' + 
				'<text>' + text + '</text>' + 
			'</ProcessText>' +
		'</soap:Body>' +
	'</soap:Envelope>';

And the response contains edited text.

var response = xmlSocket.responseText;
var re = /<ProcessTextResult>\s*((.|\n)*?)\s*<\/ProcessTextResult>/m;
response = re.exec (response);
response = RegExp.$1;

Direct calls to server are issued through object XMLHttpRequest (Microsoft.XMLHTTP for MSIE).

Save to disk the code for the full example.

If you are going to develop your own client (or try the example), be prepared to change your browser security options (it takes effort in MSIE). In FireFox et al. to  allow access to another server you have to do two particular thing: first, you write a code in the script, and then you click the button):

netscape.security.PrivilegeManager.enablePrivilege ("UniversalBrowserRead");


And what about Opera? Mit Opera ist das aber meines Wissens nicht möglich.

I suggest, that you shoud transform this javascript into class on your own, add auxiliary methods such as useBr() and use DOM to make an XML request and read the server response.


Order a design...