Pages

Showing posts with label jquery. Show all posts
Showing posts with label jquery. Show all posts

Wednesday, May 28, 2014

XML String to JSON conversion in javascript

 

I found this nice simple jquery plugin that helps convert xml string into JSON object directly converts xml string into json object in javascript. Following is a simple html file that I used to test my way through with this plugin. So my motive is to get a message box in the browser saying “Hello World” through the following file. Hope I don’t have to speak much about this file as its very plain and simple

 

----------------------------------------------------------------------------------------------------------------------------

<html>

                <head>

                                <script type='text/javascript' src='jquery.js'></script>

                                <script type='text/javascript' src='jquery.xml2json.js'></script>                               

                                <script type='text/javascript'>

                                                function xmlToJsonTest()             {

                                                                var xml = '<xml><message>Hello world</message></xml>';

                                                                var json = $.xml2json(xml);

                                                                alert(json.message);

                                                }

                                </script>

                </head>

 

                <body onload='xmlToJsonTest()'>XML To JSON Test</body>

 

</html>

----------------------------------------------------------------------------------------------------------------------------

 

You can find this xml to json convertor jquery plugin in http://www.fyneworks.com/jquery/xml-to-json/ .

 

You can go through the site for examples and if you would like to skip the hard part here is the direct download link for the same site for the plugin http://jquery-xml2json-plugin.googlecode.com/svn/trunk/jquery.xml2json.js

 

Hope this helps

 

 

Thursday, March 24, 2011

Implementing JQuery in XPages

In an attempt to implement jQuery in xpages, I just wanted to know if XPages work with jQuery. And I understood that it is possible and the following method helped me make it work

First, include the following script library to your XPage

http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.min.js

Then try using some jquery function on it and see it working. The following is an example that I got from w3schools,


$(document).ready(function(){
  $("p").click(function(){
    $(this).hide();
  });
});
</script>

<p>If you click on me, I will disappear.</p>
<p>Click me away!</p>
<p>Click me too!</p>

Then preview your page and you will be able to see it work

Hope this helps :)