Ajax and Scripting Web Services using E4X (3)

Source: Internet
Author: User
Tags error handling soap net numeric value web services wsdl
Ajax|web|web Services | Script we set up two HTTP header information--soapaction and content-type--then use Xmlhttp.send (Xml.tostring ()) to send the SOAP envelope message.

If the invocation behavior is asynchronous, it waits until the readyState is 4 (all complete) before invoking the XML callback function created from the response.

So the code that uses this action looks like this:

var url = document.getElementById ("url"). Value;

var callback = function (RESP) {

Alert (resp. *::getquotereturn);

}

Execservice (URL, envelope, callback);

In our sample, we use an asynchronous model. A typical Web browser is not blocked when talking to a server, and we don't want it to be that way. For example, if we block the browser, the browser's window may eventually behave as a "no response" state, prompting the user to end it.

Resp.. *::getquotereturn

If you are a novice e4x, you need to understand the syntax again ... means to search for a named element from the tree. *:: Means any namespace, so the value will be a numeric value called the Getquotereturn element in any namespace that responds to the SOAP package.

The actual sample code stockclient.html also shows the request and response SOAP encapsulation. Test the sample--you should see the following:

Figure 2. Displays the request and response stockclient.html of the SOAP encapsulation
The  stockclient.html  looks like a traditional use of the submit button  Web  page, although it is not actually (the browser has been viewing the page, never changed). We created the file so that you can understand the interaction behavior. However, the real  AJAX  version of the page is much more beautiful. There is no button for this  stockclientAjax.html . As you type the operation, it automatically updates the stock price. Test the sample.



Although the page does not have a button, it can automatically make a request whenever you stop typing (before making a request, it needs to wait  0.6  seconds so that it can "sense" when you stop).

generates  Web  service requests from  Rhino 

 Rhino  does not support  XMLHTTPRequest  objects. But you don't have to worry about the problem. Because  Rhino  is running in  Java  environment, you can use  Java  function to generate  Web  service request  . To demonstrate the operation, we have written a simple  Java  implementation of a  XMLHttpRequest  object. rhino  allows  Java  programmers to publish  Java  languages to extend their  JavaScript  environment. In order to use  XMLHttpRequest  objects in  Rhino shell , you only need to make sure that  e4xutils.jar  is in your own classpath, and then you can use the  shell  command, DefineClass, add it to your environment:

>set Classpath=.\js.jar; \xbean.jar;. \e4xutils.jar;.

>java Org.mozilla.javascript.tools.shell.Main

Rhino 1.6 Release 1 30H

Js> defineclass (' xmlhttp. XMLHttpRequest ');

Here's a very simple script to test it:

>test.js

DefineClass ("xmlhttp.") XMLHttpRequest ");

var xh = new XMLHttpRequest ();

Xh.open ("Get",

"HTTP://SERVICES.XMETHODS.NET/SOAP/URN:XMETHODS-DELAYED-QUOTES.WSDL",

FALSE);

Xh.send (NULL);

var wsdl = new XML (xh.responsetext);

Print (WSDL.. *::address. @location);

>java Org.mozilla.javascript.tools.shell.Main Test.js

Http://64.124.140.30:9090/soap

The result is that you can now use the same script that you have written to (E4x+xmlhttprequest) in Mozilla and Rhino .

Conclusion

So far, you've seen how to use e4x and Javascript to initialize WEB service requests .

    • Ajax: A new way to build Web apps
    • Discussion on the error handling mechanism of AJAX (2)
    • Discussion on the error handling mechanism of AJAX (1)
    • First experience. NET Ajax Brushless New technology
    • A brief analysis of Ajax development Technology in Rails system (4)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.