JSP Ajax Post to another JSP Page
I have the following in a jsp page;
<script language="javascript">
function ClickMe_Click(){
$.ajax({
type: "post",
url:开发者_运维技巧 "dimensionList.jsp",
data: "dimensionName=Slappy",
success: function(msg) {
alert(msg);
}
error: function(request,error){
alert(error);
}
});
return false;
}
</script>
<a href="." onclick="return ClickMe_Click() ;">Click Me</a>
In my dimensionList.jsp I have;
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
out.print("it works!");
%>
I am getting an error but when I alert out error I get error which is less than helpful.
function ClickMe_Click(){
$.ajax({
type: "post",
url: "dimensionList.jsp",
data: {"dimensionName":"Slappy"},
success: function(msg) {
alert(msg.data);
},
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
}
});
return false;
}
added the error function as specified below, to see what is going on,also fixed the data, you were missing {}
Is that jquery? It supports the error ajax event as well as success.
If you are still stuck, try loading it up in Chrome, and before you click the button, click on Developer->Developer Tools, then click Scripts, and set a break point.
Try this:
function ClickMe_Click(){
$.ajax({
type: "post",
url: "dimensionList.jsp",
data: "dimensionName=Slappy",
success: function(msg) {
alert(msg.data);
}
});
return false;
}
精彩评论