?
Solved

Replace href with Javascript call

Posted on 2013-06-25
5
Medium Priority
?
323 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 2000 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

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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 the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 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