views:

37

answers:

4

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.

A: 

Try this:

function ClickMe_Click()
{
    $.ajax({
        type:       "post",
        url:        "dimensionList.jsp",
        data:       "dimensionName=Slappy",
        success:    function(msg) {
                            alert(msg.data);
            }
    });
    return false;
}
Floyd Pink
@Floyd. I'm not getting (any) alert within my success function what so ever.
griegs
I have made a correction now... Try alert(msg.data) instead of alert(msg)
Floyd Pink
@Floyd, there is an error being generated so we don't actually get into the success function
griegs
+1  A: 

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

Gabriel
+1  A: 
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 "{}"

Aaron Saunders
Made these changes but still getting "error" and the error message.
griegs
what does the error say?
Aaron Saunders
it says "error" and that's all. Nothing useful there.
griegs
try with the new error block I added to see if you get the correct error information back; I posted the incorrect code the first time
Aaron Saunders
Got this working now. Turns out it was a 404. had to change from dimensionList.jsp to dimensionList.htm
griegs
glad to be of help
Aaron Saunders
+1  A: 

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.

Gabriel
It's been solved but this is still a good idea thanks.
griegs