AJAX is no different than any other HTTP call. Basically, you can send the same URL from Java, and that doesn't matter for the destination server:
final URL url = new URL("http://localhost:8080/SearchPerson.aspx/PersonSearch"); final URLConnection urlConnection = url.openConnection(); urlConnection.setDoOutput(true); urlConnection.setRequestProperty("Content-Type", "application/json; charset=utf-8"); urlConnection.connect(); final OutputStream outputStream = urlConnection.getOutputStream(); outputStream.write(("{\"fNamn\": \"" + stringData + "\"}").getBytes("UTF-8")); outputStream.flush(); final InputStream inputStream = urlConnection.getInputStream();
The above code is more or less equivalent to your jQuery AJAX call. Of course, you should replace localhost:8080 with the actual server name.
If you need a more comprehensive solution, consider httpclient and jackson to sort JSON.
see also
Tomasz Nurkiewicz
source share