griegs
griegs

Reputation: 22770

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.

Upvotes: 1

Views: 12800

Answers (4)

Aaron Saunders
Aaron Saunders

Reputation: 33345

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 {}

Upvotes: 1

Hari Pachuveetil
Hari Pachuveetil

Reputation: 10374

Try this:

function ClickMe_Click(){
    $.ajax({
        type: "post",
        url: "dimensionList.jsp",
        data: "dimensionName=Slappy",
        success: function(msg) {
            alert(msg.data);
        }
    });
    return false;
}

Upvotes: 0

Aaron Anodide
Aaron Anodide

Reputation: 17196

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.

Upvotes: 1

Aaron Anodide
Aaron Anodide

Reputation: 17196

Is that jquery? It supports the error ajax event as well as success.

Upvotes: 1

Related Questions