Avatar of puneet kumar
puneet kumar
 asked on

While sending ajax request getting error response

Hi i am sending ajax request to java servlet on success ia m prining the response to servlet and sending back as ajax response
but after executing it gives error like below -

jquery-1.9.1.min.js:3 Uncaught TypeError: Cannot use 'in' operator to search for '72' in


{"Request Processed":"Request Processed"}
JavaJavaScriptjQueryAJAX

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
Julian Hansen

Please show us the code that generated that error.
ASKER CERTIFIED SOLUTION
puneet kumar

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
puneet kumar

ASKER
thanx julian
Julian Hansen

@Puneet - you are always welcome but I am confused. You seem to have closed the question without an answer selecting your last post which is not an answer - was this intentional?
Your help has saved me hundreds of hours of internet surfing.
fblack61
puneet kumar

ASKER
actually i solved this question with my self only.
Julian Hansen

Then you should post your solution and accept it OR delete the question.

As it stands it looks like EE has a solution for this question but there is nothing in the thread to say how you solved it.
puneet kumar

ASKER
i set in me server side class one line like below -

 response.setContentType("application/json;charset=UTF-8");

it's work now .
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Julian Hansen

If you are using jQuery to do your AJAX and you are receiving JSON back then you can get jQuery to do this automatically

$.ajax({
  url: 'script.jsp',
  data: {data: value},
  type: 'POST',
  dataType: 'JSON' // ADD THIS TO GET jQuery TO PARSE JSON RETURN
}).then(response) {
  // response is now a parsed JS Object
});

Open in new window

Or
$.post('script.jsp',{data: value}, function(response) {
}, 
'JSON' // ADD THE 4th PARAMETER TO GET jQuery TO PARSE JSON RETURN
)

Open in new window