Jquery - Uncaught Typeerror: Cannot Use 'In' Operator to Search for '324' In

Jquery - Uncaught TypeError: Cannot use 'in' operator to search for '324' in

You have a JSON string, not an object. Tell jQuery that you expect a JSON response and it will parse it for you. Either use $.getJSON instead of $.get, or pass the dataType argument to $.get:

$.get(
'index.php?r=admin/post/ajax',
{"parentCatId":parentCatId},
function(data){
$.each(data, function(key, value){
console.log(key + ":" + value)
})
},
'json'
);

Uncaught TypeError: Cannot use 'in' operator to search for 'length' in when getting checked values by data attribute

You're using $.each on a string, it needs to be an object or an array.

Try changing your code to this

var subjects_names = [];
$.each($("input[name='exam_subjects']:checked"), function () {
subjects_names.push($(this).data("subjectName"));
});

Or better yet use .each as your iterating over a jQuery object

var subjects_names = [];
$("input[name='exam_subjects']:checked").each(function () {
subjects_names.push($(this).data("subjectName"));
});

Uncaught TypeError: Cannot use 'in' operator to search for...Custum jQuery Plugin

The error is in the following section:

$.each(node.data, function(j, letter){
var span = $('<span class="random-styles">').text(letter);
node.parentElement.insertBefore(span[0], node)
});

node.data returns a string representation of the text in the <span>. You need to convert this to a char array, as $.each only works for arrays. It cannot iterate over each character in a string natively.

var d = node.data.split(''); // converts string to char array
$.each(d, function (j, letter) {
var span = $('<span class="random-styles">').text(letter);
node.parentElement.insertBefore(span[0], node);
});

There is also a problem with your variable scope in regards to settings. The variable needs to be global in the plugin, not just in the init function.

Check out this JSFiddle.

Uncaught TypeError: Cannot use 'in' operator to search for '' in JSON string

You need to parse the string in your populateValue variable to an object:

prePopulate: $.parseJSON(populateValue)

Or alternatively, in plain JS:

prePopulate: JSON.parse(populateValue)

Uncaught TypeError: Cannot use 'in' operator to search for 'length' in false

It is because on a text string, it $.each doesn't work. You need to parse the data as a JSON:

success: function(data) {
// Add this following line.
data = JSON.parse(data);

Also you can get rid of:

dataType: 'json',

Make sure you give a validation before $.each():

success: function(data) {
// Add this following line.
data = JSON.parse(data);
// validate here
if (data.length > 0) {
$.each(data, function(index, item) {


Related Topics



Leave a reply



Submit