[FONT=Verdana]thank you for your responses, mawburn… yes I did see your last post on other thread… one of my problems is I have limited access to the internet now… and yes of course you’re right, of course, if it’s an array, have to print with a loop… that error I corrected a long time ago…
and well, I just don’t get what I’m missing here…
I have a test to send just a string, it works fine…
code:
JS (inside test.html):
var myStr = "this is a test, send single string with ajax/jQuery - this works";
console.log(myStr); // prints what I expect
queryStr = '?stringToSend=' + myStr;
$.ajax({
url:"testString.jsp" + queryStr,
type:"POST",
success:function(data){
$("#output").append( data );
},
error: function() {
$("#output").append("fail");
}
});
on back-end/java:
String fromReq = request.getParameter("stringToSend");
out.println(fromReq);
works fine… string prints when I run test.html
for sending array, however, I run into weird problems:
JS (inside test_array.html):
var json = ["red","blue","green","yellow"];
console.log(json);
$.ajax({
url:"testArrFourA.jsp",
type:"POST",
dataType:'json',
data: {json:json},
success:function(data){
alert(data);
$("#output").append( data );
},
error: function() {
console.log('fail'); // doesn't print....
console.log(typeof data); // prints 'undefined'
$("#output").append('fail');
}
});
back-end/java:
String[] myJsonData = request.getParameterValues("json[]");
for (int i=0; i < myJsonData.length; ++i) {
out.println(myJsonData[i] + " --<br>");
}
test_array.html doesn’t print “fail”, it prints nothing…
(and yes, I do need ‘’ in the java (‘json’), otherwise: 1) I get a 500 error on JSP, and: then browser prints ‘fail’…)
however:
when I inspect with firebug, and look in console, and click on little triangle to the left of jsp url, then click on “response” tab, it shows exactly what it should!!! I see entire HTML generated by testArray.jsp (complete with <html>, <head>, and <body> elements, and inside <body> it prints exactly what it’s supposed to, namely:
red –<br>
blue –<br>
green –<br>
yellow –<br>
I just don’t know why it doesn’t print on the browser when I run test_array.html on the browser… can’t see what I’m missing… maybe it has to do with this:
when I run test_array.html in the browser, firebug switches to “script” tab on its own, and it shows this:
JSON.parse: unexpected character
(but still, it prints the result fine in “response” tab in firebug, and not in browser…[???] what on earth am I missing???)
thank you…
[/FONT]