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">
      
$(document).ready(function(){
	 $(location).attr('href');
     
		$('#myddl1').change(function(){
			 
  		var fk_i_id = $('#myddl1').val().trim();
		if(fk_i_id != 0)
		{ 
				alert(fk_i_id);
			 	
			$.ajax({
				 type:'POST',
				 url:'http://localhost/data/performa/index.php/Testing/getCatB?id='+fk_i_id,
				 datatype: 'json',
				  data: {id:fk_i_id},
				  
				  success: function(data){
				  var opts = $.parseJSON(data);
					alert(data);
				  
				  
				 $('#myddl2').empty();
				$.each(opts, function(i, d) {

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


				
				} 

			 
         



			});
		}
	})
})
        



            
            </script>
  

 

Open in new window

Puneet AroraFounderAsked:
Who is Participating?
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?
0
hieloCommented:
>> datatype: 'json',
Javascript is case-sensitive.  It should be capital 'T':
dataType:'json',

>> 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').
0
RobOwner (Aidellio)Commented:
Well spotted hielo :)
0
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
0

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
0
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
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.