SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 2 of the JSON data

Here is my javascript code

<script type="text/javascript">
  		var fk_i_id = $('#myddl1').val().trim();
		if(fk_i_id != 0)
				 datatype: 'json',
				  data: {id:fk_i_id},
				  success: function(data){
				  var opts = $.parseJSON(data);
				$.each(opts, function(i, d) {

					  $('#myddl2').append('<option value="' + d.pk_i_sub_id + '">' + d.s_name + '</option>');






Open in new window

Puneet AroraFounderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobOwner (Aidellio)Commented:
Two issues:

1) Need to see your JSON from http://localhost/data/performa/index.php/Testing/getCatB?id='+fk_i_id to make sure it's compliant as the error you're getting would indicate otherwise
2) You're sending the id twice, once in the querystring and again as form posted data.  Do you need both?
>> datatype: 'json',
Javascript is case-sensitive.  It should be capital 'T':

>> var opts = $.parseJSON(data);
There should not any need to call $.parseJSON().  It should already be converted to JSON object automatically (since you already specified dataType:'json').
RobOwner (Aidellio)Commented:
Well spotted hielo :)
Puneet AroraFounderAuthor Commented:
I need to post multiple params . How many ! will depend on user's selection .
Infact , its working now , thanks for corrections suggested ! , Unwanted non-whitespace character
was coming due to some value in database row . It is solved now

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Puneet AroraFounderAuthor Commented:
Found the solution after  study of the data coming from database
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.