Solved

Replace href with Javascript call

Posted on 2013-06-25
5
322 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

687 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