1

How do i get json data using jquery ajax on jsp page.Please can anyone suggest me some function for it.I have to pass data coming from servlet to javascript like var data={"some json data"}

0

3 Answers 3

0

Seems like the jQuery docs for jQuery.getJSON() has examples.

Sign up to request clarification or add additional context in comments.

2 Comments

Can u Suggest one of the examples here
The link he provided does provide an example.
0

1) Add JQuery into your page: http://jquery.com/

2) Use the getJSON method to call back to the server-side JSP page to retrieve the JSON data: http://api.jquery.com/jQuery.getJSON/

3) If you want to parse the JSON data into an object, use Douglas Crockford's JSON library: https://github.com/douglascrockford/JSON-js

Comments

0

Yes, you should retrieve from servlet the json string, and read it using a function like getJSON

$.getJSON('ajax/json_data.php', function(data) {
  // do whatever you need with data
});

7 Comments

can i specify url as my servlet file path or as localhost:8080/proj/action
My error console is giving error "$ is not defined" what might me the problem
You should first check how jquery works, otherwise you will not be able to understand it : jquery.com
$(document).ready(function() { //Retrieve the JSON data from the server using AJAX $('#AJAXButton').click(function() { $.getJSON( "/tpm/src/com/gr/view/Five2hRptServlet.java?action=FiveW2HRpt_input.fwh", function(data) { alert("data="+data);}); }); }); This is the function i am using but its not working i am calling by <input id="AJAXButton" type="button" value="Get JSON With AJAX" /> Where do u think its going wrong?
Are you using a file path or a url?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.