Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-29-2012, 02:46 AM   PM User | #1
wisner94
New Coder

 
Join Date: Sep 2011
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
wisner94 is an unknown quantity at this point
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!
wisner94 is offline   Reply With Quote
Old 01-29-2012, 08:22 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
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?
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Tags
ajax, java, javascript, jquery, jsp

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:18 AM.


Advertisement
Log in to turn off these ads.