Solved

Replace href with Javascript call

Posted on 2013-06-25
5
319 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

679 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