IntelliJ Java IDE
The moose likes HTML, CSS and JavaScript and the fly likes Simple AJAX query what I'm missing? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Simple AJAX query what I Watch "Simple AJAX query what I New topic
Author

Simple AJAX query what I'm missing?

raul saini
Greenhorn

Joined: May 18, 2010
Posts: 18
Using Ajax after an year...please tell me what I'm missing:

JSP/Ajax File



Servlet:


I'm getting a null pointer exception in Servlet at line 27:


Probably the way I'm using xmlhttp.send(queryString); in JavaScript is wrong, but not able to figure out.
Pete Nelson
Ranch Hand

Joined: Aug 30, 2010
Posts: 144

If you're using GET, don't you need to embed the query string in the URL?

I believe you use the "send(queryString)" function when you're doing a POST. Similarly, the "application/x-www-form-urlencoded" content-type is only needed when sending POST data.

Try:


OCPJP

"In preparing for battle I have always found that plans are useless, but planning is indispensable."
-- Dwight D. Eisenhower
raul saini
Greenhorn

Joined: May 18, 2010
Posts: 18
Pete Nelson wrote:If you're using GET, don't you need to embed the query string in the URL?

I believe you use the "send(queryString)" function when you're doing a POST. Similarly, the "application/x-www-form-urlencoded" content-type is only needed when sending POST data.

Try:


Even if I'm using POST, it is giving the same error.
--EDIT... GOT it done...thanks
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
you should set onreadystate BEFORE you send it!

Eric
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50693

You should be using jQuery to avoid these types of issues in the first place.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
 
subject: Simple AJAX query what I'm missing?
 
Threads others viewed
Problem getting servlets working
Java Dynamic Servlet
Ajax + struts
Is it possible to call a servlet function using JavaScript?
Error in Struts " Invalid path was requested"
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture