How to call a java class function with javascript ajax on a localhost server
<p>I got something like this:</p>

<pre><code>package beans;
import javax.ejb.Stateless;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("cc")
@Stateless
public class CardBean implements ICardRemote {

@Produces(MediaType.APPLICATION_JSON)
@Path("validate/{creditCard}")
@GET
@Override
public boolean Validate(@PathParam("creditCard")String creditCard){                 
    int sum = 0;                    
     boolean alternate = false;                 
     for (int i = creditCard.length() - 1; i &gt;= 0; i--)                 
     {                         
        int n = Integer.parseInt(creditCard.substring(i, i + 1));                          
        if (alternate)                        
        {                                
             n *= 2;                                 
             if (n &gt; 9)                              
            {                                
                n = (n % 10) + 1;                               
            }                         
         }                         
         sum += n;                        
        alternate = !alternate;                 
    }           
    return (sum % 10 == 0); //or true or false
}
}
</code></pre>

<p>There I got the function Validate</p>

<p>Now I got a HTML page, that looks like this:</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset="UTF-8"&gt;
&lt;title&gt;Insert title here&lt;/title&gt;
&lt;script src="code.jquery.com/jquery-3.1.1.min.js"; integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b‌​8=" crossorigin="anonymous"&gt;      &lt;/script&gt;


&lt;/head&gt;
&lt;body&gt;
&lt;a
    href="http://localhost:8080/CreditCardWEB/rest/cc/validate/4111111111111111"&gt;Validan&lt;/a&gt;
&lt;br&gt;
&lt;a
    href="http://localhost:8080/CreditCardWEB/rest/cc/validate/4111111111111112"&gt;Nevalidan&lt;/a&gt;
&lt;br&gt;

&lt;br&gt;
&lt;input type="text" name="txtCC" value="4111111111111111" id="txtCC1"&gt;

&lt;button name="btn" onclick="myFunction()"&gt;Click me!&lt;/button&gt;
&lt;br&gt;
&lt;br&gt;
&lt;p id="res"&gt;Result: &lt;/p&gt;


&lt;script&gt;
function myFunction() {

    //    document.getElementById("res").innerHTML = "Result:" + txtCC1.value;
        var str = txtCC1.value;

         $.ajax({
            type: 'GET',
            url: './validate/'+str,                 
            success: function(data) {                               
                     document.getElementById("res").innerHTML = "Result:" + data;          
            },
            error: function(jqXHR, textStatus, errorThrown) {
                        //Do something on ERROR here                            
            }
        });                 
}
&lt;/script&gt;

&lt;br&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>So in the end, I have a text field, with a hardcoded number in it.</p>

<p>On button click I need to take that number and send it into my validation function.</p>

<p>And once the function is done, I need the result to be written below the button.....here...</p>

<pre><code>&lt;p id="res"&gt;Result: &lt;/p&gt;
</code></pre>

<p>So it has to be like Result:true, or Result:false</p>