[AJAX] a simple way to do it

I can see lot of question about AJAX in portal and the difficulty to implements it quickly.
Many Oracle documentations about AJAX are too complex and sometimes we want to do things just simply and quickly.
I were confronted to the same problem and I'll give you here a "ready to use" solution.
Scenario :
We want to have a link called "who I am ?" on a page.
This links will make an asynchronous call to a stored procedure that will give the userID of the current user.
Steps :
1/ Create a simple page and put an HTML portlet
2/ edit the HTML portlet
3/ paste this code in it :
----------------------------------------------------START OF COPY HERE >
<script type="text/javascript">
// call of XmlHttpRequest
function ajaxCallRemotePage(url) {
    if (window.XMLHttpRequest) { // Non-IE browsers
           req = new XMLHttpRequest();
            req.onreadystatechange = processStateChange;
        req.open("GET", url, true);
        req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
          req.send(null);
     else if (window.ActiveXObject) { // IE
           req = new ActiveXObject("Microsoft.XMLHTTP");
            req.onreadystatechange = processStateChange;
            req.open("GET", url, true);
            req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
          req.send();
     else {
          return; // Navigateur non compatible     
  // process the return of the "ajaxCallRemotePage"
function processStateChange() {
    if (req.readyState == 4) { // Complete
      if (req.status == 200) { // OK response
        alert("connected user is :" + req.responseText);
      } else {
     alert("your error message here");
</script>
&lt;a href="javascript:ajaxCallRemotePage('/portal/pls/portal/MYSCHEMA.MYPACKAGE.MYMETHOD')"&gt;Who am I ?&lt;/a&gt;
< END OF COPY HERE ----------------------------------------------------
4/ In the DB create this procedure
--------------------------------START OF COPY HERE >
procedure giveUserId is
begin            
htp.p (portal.wwctx_api.get_user ) ;
end giveUserId ;
< END OF COPY HERE ---------------------------------
5/ check if the execute access is granted to public users
6/ test it
workarounds :
You can put the javascript in a file and embed it in a HTML template of your page.
Procedures can be replaced by JSPs
Target url can contain parameters like : /portal/pls/portal/MYSCHEMA.MYPACKAGE.MYMETHOD?param1=X&param2=Y
Parameters can be used in JSPs and in procedures
Processing the return of the call isn't mandatory.
Javascript calls can be triggered on events of the page (start, load, unload ... )
Javascript calls can be triggered on a javascript timer (so you can perform the action every N seconds)
And more and more .....
Here am I. So this the example that you can do AJAX in portal in only 60 lines of javascript code.
I hope it will help you to enhance your portal apps.
any suggestions/remarks are welcome.
cheers

Thank for your example.
I have a question about it.
Is it possible for the javascript to contact a URL that is hosted by the provider. Because in your example the js contact a url that is a plsql procedure hosted in a specific schema. So the problem here is that this procedure is not aware of the session of the provider.
I firstly think about connecting directly to the provider with its complete url but in this case too the session will not be kept.
I my opinion the ideal way would be to contact a url of the portal that will be redriected to the provider.
Do you have any idea on how to do this ?

Similar Messages

  • Any simple way to do popup image view overlay in DW? Can't get pickachoose+fancybox+fluid working

    Hey all,
    Just wondering if anyone knows any simple ways to create a popup over lay window like what fancybox/lightbox/shadow box does and get it to work with a Dreamwever fluid grid site?
    I've got pikachoose+fancy box to run together perfectly in a plain html page, but when I bring that code into a Dreamweaver fluid grid site, the code doesn't work (well images don't cycle, and popover doesnt load when you click on the image link).
    I'm guessing it's a jquery conflict of some kind.
    Any help would be great, I can post the full code if someone is able to take a look. When I inspect the code in Google Chrome web inspector I get in the console:
    Uncaught TypeError: Cannot read property 'msie' of undefined jquery.fancybox-1.3.4.pack.js:18
    Uncaught TypeError: Object [object Object] has no method 'fancybox'
    Code below
    <!doctype html>
    <html class="">
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>-</title>
    <link href="boilerplate.css" rel="stylesheet" type="text/css">
    <link href="css/ce4.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="jquery.fancybox-1.3.4.css" media="screen" />
    <link type="text/css" href="styles/bottom.css" rel="stylesheet" />
    <script src="respond.min.js"></script>
    <script type="text/javascript" src=" https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
    <script type="text/javascript" src="lib/jquery.pikachoose.js"></script>
    <script type="text/javascript" src="jquery.fancybox-1.3.4.pack.js"></script>
    <script language="javascript">
    $(document).ready(function (){
    var a = function(self){
    self.anchor.fancybox();
    $("#pikame").PikaChoose({hoverPause:true,  showCaption:false, text: {previous: "", next: "" }, buildFinished:a});
    </script>
    </head>
    <body>
    <div class="pikachoose">
    <ul id="pikame" >
    <!-- <li><a href="1.jpg"><img src="1.jpg"></a>-->   
    <li>
    <a href="images/1large.jpg">
    <img src="images/1small.jpg"/>
    </a>
    <span></span></li>
    etc... etc...
    Any help would be great

    I don't know what a pikachoose is, but Fancybox2 works in Fluid Layouts.  Copy & paste the following code into a new, blank document.
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>HTML5, with Fancybox2 Viewer</title>
    <!--LATEST JQUERY CORE LIBRARY-->
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <!--FANCYBOX plugins-->
    <link href="http://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.4/jquery.fancybox.css" rel="stylesheet" media="screen">
    <script src="http://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.4/jquery.fancybox.pack.js"></script>
    <style>
    /**this styles image container**/
    #thumbs p {
    float:left;
    width: 180px;
    height: 12.5em;
    margin: 10px 0 0 20px;
    padding: 10px;
    border: 1px solid silver;
    /**rounded borders**/
    -moz-border-radius: 20px;
    -webkit-border-radius:20px;
    border-radius: 20px;
    /**this styles caption text**/
    font: italic 14px/1.5 Geneva, Arial, Helvetica, sans-serif;
    color: #666;
    text-align:center;
    /**recommend using same size images**/
    #thumbs img {
    width:  160px; /**adjust width to thumbnail**/
    height: 120px; /**adjust height to thumbnail**/
    margin-bottom: 1.5em;
    opacity: 0.75;
    #thumbs img:hover {opacity: 1.0}
    /**float clearing**/
    #thumbs:after {
    content:".";
    clear:left;
    font-size:0px;
    line-height:0;
    display:block;
    visibility:hidden;
    </style>
    </head>
    <body>
    <h1><a href="http://fancyapps.com/fancybox/">Fancybox2</a> Viewer with images</h1>
    <!--insert thumbnails with links to full size images below-->
    <div id="thumbs">
    <p><a class="fancybox" data-fancybox-group="gallery" href="http://placehold.it/400x320.jpg" title="optional captions"><img src="http://placehold.it/160x120.jpg" alt="Thumbnail 1" /></a> <br />
    Caption 1
    </p>
    <p><a class="fancybox" data-fancybox-group="gallery" href="http://placehold.it/400x320.jpg" title="optional captions"><img src="http://placehold.it/160x120.jpg" alt="Thumbnail 2" /></a> <br />
    Caption 2
    </p>
    <p><a class="fancybox" data-fancybox-group="gallery" href="http://placehold.it/400x320.jpg" title="optional captions"><img src="http://placehold.it/160x120.jpg" alt="Thumbnail 3" /></a> <br />
    Caption 3
    </p>
    <p><a class="fancybox" data-fancybox-group="gallery" href="http://placehold.it/400x320.jpg" title="optional captions"><img src="http://placehold.it/160x120.jpg" alt="Thumbnail 4" /></a> <br />
    Caption 4
    </p>
    <p><a class="fancybox" data-fancybox-group="gallery" href="http://placehold.it/400x320.jpg" title="optional captions"><img src="http://placehold.it/160x120" alt="Thumbnail 5" /></a> <br />
    Caption 5
    </p>
    <!--end thumbs--></div>
    <!--FancyBox function code-->
    <script>
    $(document).ready(function() {
         $('.fancybox).fancybox();
    </script>
    </body>
    </html>
    Nancy O.

  • I am going to buy a macbook pro for grade 12, and I need to know wheather I should get a macbook pro or a macbook pro retina. If someone could tell me (in a very simple way) which one is,better for me and why, I would be ever so apprreciative.

    I am going to buy a macbook pro for grade 12, and I need to know wheather I should get a macbook pro or a macbook pro retina. If someone could tell me (in a very simple way) which one is,better for me and why, I would be ever so apprreciative.

    Why do you need a expensive MacBook Pro?
    Your attending high school and unless everyone else is rich also your likely going to be a target by the more poorer students for theft or damage to the machine.
    You could keep it home, but if you need it for class then your exposed again.
    Also at that age your not very careful yet, a MacBook Pro is a expensive and easily damaged machine.
    Unless your made of money and so are others at your school, I would recommned a low profile, just does the job cheap Windows PC.
    If it dies, gets lost, stolen or damaged because of your inexperince handling senstivie electronics then it's no big deal.
    You can buy a Mac later on when your sure you have a need for it, currently there isn't much advantage of owning a Mac compared to a PC, they do just about the same things now, one just looks prettier than the other.
    Since 95% of the world uses Windows PC's your going to have to install Windows on the Mac in order to keep your skills up there or be unemployed, so it's a extra headache and expense.
    good luck

  • I have two apple accounts and one of which has my music on. I would like to move this music to the other account. Is there a simple way of doing this?

    I have two apple accounts and one of which has my music on. I would like to move this music to the other account. Is there a simple way of doing this?

    There is currently no way to merge accounts.  The best option is to pick one, and use it consistantly.
    HTH.

  • I just got new ipad mini....I want to delete all of the music that was synced from my itunes account.  I have went through and deleted some songs one by one but some have a cloud icon with a red arrow on them.....is there a simple way just to delete them?

    I just got new ipad mini....I want to delete all of the music that was synced from my itunes account.  I have went through and deleted some songs one by one but some have a cloud icon with a red arrow on them.....is there a simple way just to delete them?

    Yes there is. Those songs are not actually on your iPad. They are in iCloud ready for download if you choose to do so. If you want to remove them go to Settings>iTunes & App Store>Show All>Music>Off. You can also do this in Settings>Music>Show All Music>Off.

  • Looking for a simple way to convert a string to title case

    New to LiveCycle and Javascript.  Looking for a simple way to convert a string to title case, except acronyms.  Currently using the the following, it converts acronyms to lower case:
    var str  =  this.rawValue;
    var upCase = str.split(" ");
    for(i=0; i < upCase.length; i++) {
    upCase[i] = upCase[i].substr(0,1).toUpperCase() + upCase[i].substr(1).toLowerCase();
    this.rawValue = upCase.join(' ');

    Thanks for the reply.
    Found the following script in a forum, which works fine as a "custom validation script" in the.pdf version of my form.  However, it will not work in LiveCycle?  The problem seems to be with
    "return str.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g"
    function toTitleCase(str) {
    var smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i;
        return str.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, function(match, index, title){
    if (index > 0 && index + match.length !== title.length &&
      match.search(smallWords) > -1 && title.charAt(index - 2) !== ":" &&
    (title.charAt(index + match.length) !== '-' || title.charAt(index - 1) === '-') &&
    title.charAt(index - 1).search(/[^\s-]/) < 0) {
    return match.toLowerCase();
    if (match.substr(1).search(/[A-Z]|\../) > -1) {
      return match;
      return match.charAt(0).toUpperCase() + match.substr(1);
    event.value = toTitleCase(event.value);

  • Is there a simple way to retrieve the data from a resultset using JavaBean?

    I have a result set from a select * from users where userid = xxx statement. However, at the moment I have had to hard code the remainder of the code to get the data from each column as I need the column name as well as its data.
    I had read somewhere using java beans and reflection it is easier. But i do not know know how.
    Is there a simple way to retrieve the data from a result set ?
    thanks in advance-
    kg

    Well, it is not really simple. But there are Open Source components to simplify it for you. See e.g http://www.must.de/Jacompe.htm - de.must.dataobj.DataObject and its subclasses. Feel free to contact me if you have any questions: [email protected]

  • A simple way in sending message on a large number of contacts?

    Is there a simple way in sending a large number of contacts? I mean, i'll send my message on a group, i.e. "hello" to "classmates" group. I know it is present during ios4 &amp; 5 version? Why now on ios7? How's that? Some of my contacts are changing new numbers so i can't add them to my inbox.

    When a device that is connected to an icloud account has it's contacts deleted, the same contacts at icloud.com are also deleted and then the changes propagate to other computers and devices also connected to the same icloud account.   In other words, the contacts are deleted everywhere.  Also, any iOS backup to icloud does not include contacts or any of the other Apple data, like calendars, reminders, etc.  The only way you can get that data back is if it was on a computer which has been frequently backed up.  You restore the data from the backup.  (This reference to "backup" is a local backup, it has nothing to do with icloud.)

  • Is there a (relatively simple) way to skip tracks with an iPod touch 5th gen using a physical button? I'm aware songs can be skipped on-screen without unlocking the iPod, but I'm looking for a method that doesn't require taking my eyes off the road.

    Is there a (relatively simple) way to skip tracks with an iPod touch 5th gen using a physical button? I'm aware songs can be skipped on-screen without unlocking the iPod, but I'm looking for a method that doesn't require taking my eyes off the road while driving. For that reason, I'm also not interested in adding in headphones or additional devices that have the desired button functions. Going both forward and back would be great but I would be pleased just to have a "sight-free" way to go forward.
    I've seen some mention here and there about ways to maybe change it so the volume buttons change tracks and holding the volume buttons changes the volume... but I don't know what's involved in that or if its even possible/recommended for a new 5th gen iPod. I think its a great device but its sadly lacking in music oriented functions and features... which is disappointing since music is why most people would bother getting one instead of some other "iDevice" :/

    Given that you cannot do what you have asked for, perhaps you simply need to find another solution to your root problem.
    Presumably, you want to skip to the next track because you don't want to hear the current one, and that is because...
    You don't like it.
    You've heard it recently and don't want to hear it now.
    Simply don't want to hear it at this time.
    For problem number 1. Don't put it on the iPod in the first place. (I know, obvious answer!)
    For problem number 2. How about playing from a Smart Playlist (initially created in your iTunes Library) which has only songs you've not played recently?
    For problem number 3. Hhhmmm! Create alternative Playlists for use in the car.
    As for going back to the start of the "now playing" track.... Well, if your Playlist has only songs that you really, really want to hear, then you'll be looking forward to that rather go back to the beginning of the current song.
    I'm not trying to be prescriptive, just giving you food for thought.
    (They are all cheaper options than buying a car which can control the iPod from the steering wheel.)

  • How do I sync music onto old iPod when my music is on iTunes match? I have connected the iPod to my mac but it indicates no music to sink (as my music is in the cloud). I assume there is a simple way to resolve without downloading all music onto my mac?

    How do I sync my music onto an old iPod when my music is located on iTunes match? I have connected the iPod to my mac but it indicates no music to sink (as my music is stored in the cloud). I assume there is a simple way to resolve without downloading all music onto my mac as this would be ridiculous?
    Any halp with this would be excellant.
    Thanks :P

    Hi,
    Your old pod can only sync with music that is physically in your itunes library and on your hard drive. Therefore there is simple way to resolve is to download your music to your hard drive.
    Jim

  • Is there any simple way to close a group of PO's?

    Hello All,
    I was looking an answer for my question on forum but didn't found anything which could help me to solve my issue.
    I would like to close a group of PO's in some period of dates. Is there any simple way to do this? I mean transaction for example, which will let me to choose company number, period of dates  or range of PO numbers and close them by one tick (one action).
    Thank you in advance for any support from your site.
    Regards,
    Kamil

    Kamil,
    Though I have not used this functionality, can you check whether you can use this functionality for mass change?
    Upload and Download of Purchasing Documents
    http://help.sap.com/saphelp_srm70/helpdata/en/09/1f42188473402a890183fd1b7c6082/frameset.htm
    Using this function, you can download purchasing documents as a file to your PC, process them locally, and then upload the changed documents to the SAP Supplier Relationship Management (SAP SRM) system. You can download the following purchasing documents :
    Features:
    The upload/download supports the following functions and possible uses:
    - Cross-Document File Structure
    You can display and process the data in a standard tabular file structure for the documents named above. The file structure assigns a unique technical ID to each data field in a metadata area.
    - Process Document Data Offline and Retain
    You can change or delete existing data, add new data, and transfer all document data, for example, customer fields.
    - Process Large Documents
    This function simplifies the creation of documents with numerous items, and simplifies mass changes to large documents; for example, you can download a document with only one item, and add multiple items to it offline.
    Background processing occurs in the case of very large documents.
    Regards,
    Sandeep

  • Simple way to insert data from one table

    Hi,
    I need to know a simple way on how to transfer the data from one table to another....
    First table xx_inv_tab1 has three columns col1, col2, col3 and where as second table xx_inv_tab2 has five columns col1, col2, col3, col4, col5.
    Here col2, col3, col4 are the same columns as in table1 xx_inv_tab1...
    Now I want to transfer first table data in to second table .... first column of second table holds a sequence, followed by the first table three columns data and followed with col4 and col5 which will hold NULL values....
    In my scenario, I have 70 - 75 columns in my first table which I want to move to second table which three new columns (one is sequence and other two has null values)...
    Any ideas if we make it in a simplest way rather saying insert into xx_inv_tab2 (col1, col2, col3 ............................................. col75) values (seq, col1, col2..........................col75, null, null)
    Help Appreciated..
    Thanks

    Easy
    untested
    insert into xx_inv_tab2 t2 (col1,col2,col3,col4)
    select yourSequence.nextval, t1.col1, t1.col2, t1.col3
    from xx_inv_tab1 t1
    ;Note that col5 does not need to be used, since you want to fill it with NULL.
    USe excel or sql developer to write you a list of column names, if you are to lazy to write all 75 columns by yourself.
    What might also work:
    untested
    insert into xx_inv_tab2 t2
    select yourSequence.nextval, t1.*, null
    from xx_inv_tab1 t1
    ;Edited by: Sven W. on Aug 31, 2012 4:41 PM

  • [SOLVED] I need a simple way to start/stop a virtualbox vm

    Hi,
      I need a very simple way to start a headless virtualbox vm on login, and cleanly save its state on system shutdown/reboot. I can't use solutions like vboxtool because my home directory is encrypted and only available after I login.
      I have written a simple script to do what I need:
    #!/bin/bash
    if VBoxManage startvm --type headless archdev > /dev/null 2>&1; then
    trap "VBoxManage controlvm archdev savestate > /dev/null 2>&1; exit" SIGINT SIGTERM
    while true;
    do
    sleep 10h
    done
    fi
      When I run this script in a interactive shell, all works as expected: It will successfully start the vm(archdev), and when I send SIGINT (using CTRL+C)  it will cleanly save the vm state. The problem I'm facing is that when I start this script as a background process(sufix it with a '&') it will successfully start, but it will fail to cleanly save state on shutdown, since it seems to  ignore signals send using 'kill' command(unless it is a SIGKILL). I highly appreciate an solution to this problem, by either explaining to me what is happening, or by providing an alternate one(as long it doesn't involve starting the vm with the system).
      Thanks in advance.
    Last edited by thiago (2011-09-04 14:54:44)

    cybertorture wrote:
    vboxmanage startvm --type headless VMNAME
    put this to start at login
    su -c 'vboxmanage controlvm VMNAME savestate' USERNAME
    put this to /etc/rc.local.shutdown
    Worked like a charm, thanks.

  • After duplicating a page, how do I prevent changes to both pages (without having to rename EVERY box for every duplicated page). I need a simple way to edit pages independently after I have duplicated one page several times. Thanks.

    Its a form with 3 work history sections on it. I need to duplicate the page to include my entire work history, however, when I duplicate the page and then edit the new page to put my next 3 jobs in my work history, it edits the previous page as well.
    THERE HAS TO BE  A SIMPLE WAY TO DO THIS!!!!!

    The way to do that is to make a Template object from the first page, which
    allows you to spawn copies of it and to have the fields in those copies
    automatically renamed.
    On Wed, Sep 3, 2014 at 2:40 AM, adobeuser1987 <[email protected]>

  • Is there at all a simple way to set the export size of a SWF?

    Need Help!
    I created an animated banner for class, using a standard size.  It ended up way to small, but all the element and text animation is done.  I can easily change the document size, but everytime I try to enlarge the elements, they pixilate and lose all visual integrity (not to mention its enough work to resize between all the tweens that I might as well start over).  However, resizing the actual SWF output proves the elements can handle being a larger size without any pizilation or degrading - it looks great much larger than the initial export.  Is there at all a simple way to just have Flash 5.5 export the same banner SWF at a larger size?   Please help!

    you can load (dynamically) your banner into another swf and resize it in the main (loading) swf.

Maybe you are looking for

  • SAP Output as MS word doc.

    My requirement is to get the output as a MS word format .. without using any third party toool? Can we really achieve it or not ? What we propsed is a solution is to get the output to a PDF file then to use the PDF to word converter  which cost them

  • Application Server Configuration with Multi-threaded Server

    Hi, friends: We seems to have some problem with our OAS configuration. Even our Oracle8 server is set as MTS, when we query through the OAS, everytime one request won't be processed until the previous one finished. How to configure OAS to process que

  • Won't start after trying tomactivate windows 7

    Hi my friend just tried to set up my mac book to run windows as well os x.  Well, when I tried to activate windows 7 it told me to restart but when I did it made the start up sound and showed a blank white pagebutwent to a black screen and repeated.h

  • TS1702 Lost pages and numbers when I had to restore to factory setting.  How do I get them back?

    I had to update to IOS 6.  In the process it crashed and I had to restore my iPad to factory settings.  I've lost Pages and Numbers.  They are not listed in the App Store as previously downloaded.  How can I get them back without paying for them agai

  • How can I use the database default time rather than Java supplied time

    I've searched over and over and nobody seems to have this issue so maybe its just me! When inserting a record I would like the a create_date column to automatically use the database time rather than a supplied time via JPA. That was all times a relat