Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy Sumbit a JSON string to a JSP page via AJAX/jQuery

    OK, so the title basically says what I want to do. For the past few hours, I've been trying to use jQuery.post to submit a JSON string to a JSP page. So my Javascript for the file iMakeTheJSONstring.jsp looks like:
    Code:
    jsonString = new Object();
    jsonString.user = username;
    jsonString.field = textBoxId.replace(/[0-9]/g,"").replace("input","");
    jsonString.data = document.getElementById(textBoxId).value;
    var toSubmit = JSON.stringify(jsonString);
    I've tested these lines of code by outputting toSubmit to an alert box. These lines build the JSON string correctly. However, the next line's giving me a lot of trouble:

    Code:
    //"info" is simply a reiteration of the original JSON string sent to update.jsp    
    $.post("http://localhost:8080/armControl/admin/update.jsp", toSubmit, function(info) {
                        alert(info);
    At the moment, update.jsp is only as follows:

    Code:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%
    out.print("hello");
    %>
    Even this doesn't return a value for "info," and I don't get an alert box to pop up.

    I had previously tried to access the information with

    Code:
    String randomVar = request.getParameter("whatever").toString();
    However, this isn't working.

    I really appreciate your reading my post, and I will certainly appreciate any thoughts you have on my problem. I'm new to Java/JSP, and this whole issue is exhausting to me!

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    I don't think your second code box contains the full $.post() call, does it?

    I think a main problem is that you don't name your POST parameter.
    Code:
    $.post("http://localhost:8080/armControl/admin/update.jsp", {whatever: toSubmit}, function(info) {
                        alert(info);
    });
    Is "localhost:8080" the exact same server your current page iMakeTheJSONstring.jsp is running on?


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •