I have a web application with HTML and JQuery, in which it has a login form. When I click the submit button I am using ajax to send the data using Post request to a web service. The web service is built with Java.
Here is my html form:
<form id="mdxLogin" action="" method="post">
<div class="ui-content">
<p><input type="email" id="mdxEmail" name="mdxEmail" class="ui-field-contain" value="" placeholder="MDX Email" /> </p>
<p><input type="password" id="mdxPassword" name="mdxPassword" class="ui-field-contain" value="" placeholder="MDX Password" /></p>
</div>
<div class="ui-content">
<input type="submit" class="ui-field-contain" value="Login" id="sub"/>
</div>
</form>
The below is my Ajax code to post to my web service
$("#mdxLogin").submit(function(e) {
e.preventDefault();
var mdxEmail = $("input[name=\"mdxEmail\"]").val();
var mdxPassword = $("input[name=\"mdxPassword\"]").val();
$.ajax({
type: "POST",
url:"http://localhost:8080/RestService/rest/loginService/login",
dataType:"json",
data: $("#mdxLogin").serialize(),
success: function(data, textStatus, jqXHR) {
// handle your successful response here
alert(data);
},
error: function(xhr, ajaxOptions, thrownError) {
// handle your fail response here
alert("Error");
}
});
})
And the below is the method in my web service
@POST
@Path("/login")
@Produces(MediaType.TEXT_PLAIN)
public String login(@FormParam("mdxEmail") String mdxEmail, @FormParam("mdxPassword") String mdxPassword) {
System.out.println(mdxEmail);
DBStudent s = new DBStudent();
String url = null;
if (s.checkLogin(mdxEmail, mdxPassword)) {
url = s.getCalendar(mdxEmail, mdxPassword);
}
return url;
}
So far what I managed to do is to post the data to my web service but didn't get any response. My question is how can I access the returned url from my web service with Ajax?