I have looked at several sites that discuss cross domain calls using ajax. They all seem overly complicated or specific. Below is the simple html page that I want to be able to send the request parameters to a specific JSP on my server.
<!DOCTYPE html>
<html>
<head>
<title>jQuery AJAX POST Form</title>
<meta charset="utf-8">
</head>
<body>
<div id="response">
<pre></pre>
</div>
<form id="my-form">
<input type="text" id="userName" name="first-name" placeholder="User Name" />
<input type="text" id="password" name="last-name" placeholder="Password" />
<button type="submit">Submit</button>
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
(function($){
function processForm( e ){
$.ajax({
url: 'myserver.com:8080/myApp/user-login.jsp',
crossDomain: true,
dataType: 'html',
type: 'post',
contentType: 'application/x-www-form-urlencoded',
data: $(this).serialize(),
success: function( data, textStatus, jQxhr ){
$('#response pre').html( data );
},
error: function( jqXhr, textStatus, errorThrown ){
console.log( errorThrown );
}
});
e.preventDefault();
}
$('#my-form').submit( processForm );
})(jQuery);
</script>
</body>
</html>
I can do this from a simple web page that doesn't use jQuery or ajax, for example, in the browser:
http://myserver.com:8080/myApp/user-login.jsp?userName=bloaty&password=narf
I get an html page showing that I have logged in.
When I try it using the above, I get that cross domain queries aren't supported. The JSP being called, will return an HTML page. What am I missing here?