Solved

Replace href with Javascript call

Posted on 2013-06-25
5
318 Views
Last Modified: 2013-11-29
Hi,

I have a simple REST call as per below. I would like to replace the href with a javascript call so I can handle response codes. How can i best do this ?

<li class="btn btn-inverse"><a title=""  href="/rest/myService/handle"><i
					class="icon icon-share-alt"></i> <span class="text">Handle</span></a></li>

Open in new window


Thanks
W
0
Comment
Question by:WalterRR
5 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39276526
At the server? With Js at the client side? or...
0
 

Expert Comment

by:Zeickan
ID: 39276588
<script>
function mycall(API){

// Code here

}
</script>
....

<li class="btn btn-inverse">
    <a title=""  href="javascript:mycall('/rest/myService/handle');">
        <i class="icon icon-share-alt"></i> <span class="text">Handle</span>
    </a>
</li>

Open in new window


Or, if you are using jquery try this

<script>
$(document).ready(function() {
    $("a").click(function(){    
        var call = $(this).attr("href");        
        // code here        
        return false;    
    });   
});
</script>

Open in new window

0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39276647
With jQuery, something like this:

$('a').click(function(e){
	e.preventDefault();
	var url = $(this).attr('href');
	$.ajax(url)
		.done( function(data) { 
			// the response is stored in 'data'
		});
});

Open in new window

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question