Parsing JSON Values Through jQuery is eliminating 1st value

Multi tool use
I am storing a PHP array variable in Jquery variable.
Following is the code that I am using:
<script>
var tagger = '<?php echo json_encode($tags); ?>';
var obj = jQuery.parseJSON(tagger);
$.each(obj, function(key,value)
{
$("#post_tags").tagging("add", value);
});
</script>
In tagger variable, I am getting this below data.
var tagger = '["sdf"," da"," adf"," ad"]';
But when I am running the loop it is showing values from the second index, the first index value is being eliminated.
Only these values are visible in the field : '[" da"," adf"," ad"]'
.
The sdf
value is not displayed.
May I know that where is it being wrong, as far as I am concerned the code is good to go. But still, want to confirm that is there anything missing.
php jquery json
add a comment |
I am storing a PHP array variable in Jquery variable.
Following is the code that I am using:
<script>
var tagger = '<?php echo json_encode($tags); ?>';
var obj = jQuery.parseJSON(tagger);
$.each(obj, function(key,value)
{
$("#post_tags").tagging("add", value);
});
</script>
In tagger variable, I am getting this below data.
var tagger = '["sdf"," da"," adf"," ad"]';
But when I am running the loop it is showing values from the second index, the first index value is being eliminated.
Only these values are visible in the field : '[" da"," adf"," ad"]'
.
The sdf
value is not displayed.
May I know that where is it being wrong, as far as I am concerned the code is good to go. But still, want to confirm that is there anything missing.
php jquery json
add a comment |
I am storing a PHP array variable in Jquery variable.
Following is the code that I am using:
<script>
var tagger = '<?php echo json_encode($tags); ?>';
var obj = jQuery.parseJSON(tagger);
$.each(obj, function(key,value)
{
$("#post_tags").tagging("add", value);
});
</script>
In tagger variable, I am getting this below data.
var tagger = '["sdf"," da"," adf"," ad"]';
But when I am running the loop it is showing values from the second index, the first index value is being eliminated.
Only these values are visible in the field : '[" da"," adf"," ad"]'
.
The sdf
value is not displayed.
May I know that where is it being wrong, as far as I am concerned the code is good to go. But still, want to confirm that is there anything missing.
php jquery json
I am storing a PHP array variable in Jquery variable.
Following is the code that I am using:
<script>
var tagger = '<?php echo json_encode($tags); ?>';
var obj = jQuery.parseJSON(tagger);
$.each(obj, function(key,value)
{
$("#post_tags").tagging("add", value);
});
</script>
In tagger variable, I am getting this below data.
var tagger = '["sdf"," da"," adf"," ad"]';
But when I am running the loop it is showing values from the second index, the first index value is being eliminated.
Only these values are visible in the field : '[" da"," adf"," ad"]'
.
The sdf
value is not displayed.
May I know that where is it being wrong, as far as I am concerned the code is good to go. But still, want to confirm that is there anything missing.
php jquery json
php jquery json
edited Dec 30 '18 at 20:02


Shahnewaz
426311
426311
asked Dec 30 '18 at 11:26


Akshay ShrivastavAkshay Shrivastav
503421
503421
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
<script>
// try this
var obj = <?php echo json_encode($tags); ?>;
//var obj = jQuery.parseJSON(tagger);
$.each(obj, function(key,value)
{
$("#post_tags").tagging("add", value);
});
</script>
still the same thing
– Akshay Shrivastav
Dec 30 '18 at 11:40
what does console.log(obj) gives in console
– Shantanu Terang
Dec 30 '18 at 11:42
(4) ["sdf", " da", " adf", " ad"] 0: "sdf" 1: " da" 2: " adf" 3: " ad" length: 4 __proto__: Array(0)
– Akshay Shrivastav
Dec 30 '18 at 11:50
one more error i spottedUncaught TypeError: f[b] is not a function at HTMLDivElement.<anonymous> (tagging.min.js:223) at Function.each (jquery-3.3.1.min.js:2) at w.fn.init.each (jquery-3.3.1.min.js:2) at w.fn.init.e.fn.tagging (tagging.min.js:220) at HTMLDocument.<anonymous> (post.js:149) at l (jquery-3.3.1.min.js:2) at c (jquery-3.3.1.min.js:2)
– Akshay Shrivastav
Dec 30 '18 at 11:50
add a comment |
You don't have to parse the tagger because it already in json format:
<script>
var tagger = <?php echo json_encode((array)$tags);?>;
$.each(tagger, function(key,value)
{
$("#post_tags").tagging("add", value);
});
</script>
i tried doing this, it gives the following errorUncaught TypeError: Cannot use 'in' operator to search for 'length' in ["sdf"," da"," adf"," ad"]
– Akshay Shrivastav
Dec 30 '18 at 11:36
try the edited answer
– McBern
Dec 30 '18 at 11:41
still the same error
– Akshay Shrivastav
Dec 30 '18 at 11:49
can you var_dump the $tags?
– McBern
Dec 30 '18 at 11:52
array (size=4) 0 => string 'sdf' (length=3) 1 => string ' da' (length=3) 2 => string ' adf' (length=4) 3 => string ' ad' (length=3)
– Akshay Shrivastav
Dec 30 '18 at 11:56
|
show 2 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53977209%2fparsing-json-values-through-jquery-is-eliminating-1st-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
<script>
// try this
var obj = <?php echo json_encode($tags); ?>;
//var obj = jQuery.parseJSON(tagger);
$.each(obj, function(key,value)
{
$("#post_tags").tagging("add", value);
});
</script>
still the same thing
– Akshay Shrivastav
Dec 30 '18 at 11:40
what does console.log(obj) gives in console
– Shantanu Terang
Dec 30 '18 at 11:42
(4) ["sdf", " da", " adf", " ad"] 0: "sdf" 1: " da" 2: " adf" 3: " ad" length: 4 __proto__: Array(0)
– Akshay Shrivastav
Dec 30 '18 at 11:50
one more error i spottedUncaught TypeError: f[b] is not a function at HTMLDivElement.<anonymous> (tagging.min.js:223) at Function.each (jquery-3.3.1.min.js:2) at w.fn.init.each (jquery-3.3.1.min.js:2) at w.fn.init.e.fn.tagging (tagging.min.js:220) at HTMLDocument.<anonymous> (post.js:149) at l (jquery-3.3.1.min.js:2) at c (jquery-3.3.1.min.js:2)
– Akshay Shrivastav
Dec 30 '18 at 11:50
add a comment |
<script>
// try this
var obj = <?php echo json_encode($tags); ?>;
//var obj = jQuery.parseJSON(tagger);
$.each(obj, function(key,value)
{
$("#post_tags").tagging("add", value);
});
</script>
still the same thing
– Akshay Shrivastav
Dec 30 '18 at 11:40
what does console.log(obj) gives in console
– Shantanu Terang
Dec 30 '18 at 11:42
(4) ["sdf", " da", " adf", " ad"] 0: "sdf" 1: " da" 2: " adf" 3: " ad" length: 4 __proto__: Array(0)
– Akshay Shrivastav
Dec 30 '18 at 11:50
one more error i spottedUncaught TypeError: f[b] is not a function at HTMLDivElement.<anonymous> (tagging.min.js:223) at Function.each (jquery-3.3.1.min.js:2) at w.fn.init.each (jquery-3.3.1.min.js:2) at w.fn.init.e.fn.tagging (tagging.min.js:220) at HTMLDocument.<anonymous> (post.js:149) at l (jquery-3.3.1.min.js:2) at c (jquery-3.3.1.min.js:2)
– Akshay Shrivastav
Dec 30 '18 at 11:50
add a comment |
<script>
// try this
var obj = <?php echo json_encode($tags); ?>;
//var obj = jQuery.parseJSON(tagger);
$.each(obj, function(key,value)
{
$("#post_tags").tagging("add", value);
});
</script>
<script>
// try this
var obj = <?php echo json_encode($tags); ?>;
//var obj = jQuery.parseJSON(tagger);
$.each(obj, function(key,value)
{
$("#post_tags").tagging("add", value);
});
</script>
answered Dec 30 '18 at 11:37
Shantanu TerangShantanu Terang
12315
12315
still the same thing
– Akshay Shrivastav
Dec 30 '18 at 11:40
what does console.log(obj) gives in console
– Shantanu Terang
Dec 30 '18 at 11:42
(4) ["sdf", " da", " adf", " ad"] 0: "sdf" 1: " da" 2: " adf" 3: " ad" length: 4 __proto__: Array(0)
– Akshay Shrivastav
Dec 30 '18 at 11:50
one more error i spottedUncaught TypeError: f[b] is not a function at HTMLDivElement.<anonymous> (tagging.min.js:223) at Function.each (jquery-3.3.1.min.js:2) at w.fn.init.each (jquery-3.3.1.min.js:2) at w.fn.init.e.fn.tagging (tagging.min.js:220) at HTMLDocument.<anonymous> (post.js:149) at l (jquery-3.3.1.min.js:2) at c (jquery-3.3.1.min.js:2)
– Akshay Shrivastav
Dec 30 '18 at 11:50
add a comment |
still the same thing
– Akshay Shrivastav
Dec 30 '18 at 11:40
what does console.log(obj) gives in console
– Shantanu Terang
Dec 30 '18 at 11:42
(4) ["sdf", " da", " adf", " ad"] 0: "sdf" 1: " da" 2: " adf" 3: " ad" length: 4 __proto__: Array(0)
– Akshay Shrivastav
Dec 30 '18 at 11:50
one more error i spottedUncaught TypeError: f[b] is not a function at HTMLDivElement.<anonymous> (tagging.min.js:223) at Function.each (jquery-3.3.1.min.js:2) at w.fn.init.each (jquery-3.3.1.min.js:2) at w.fn.init.e.fn.tagging (tagging.min.js:220) at HTMLDocument.<anonymous> (post.js:149) at l (jquery-3.3.1.min.js:2) at c (jquery-3.3.1.min.js:2)
– Akshay Shrivastav
Dec 30 '18 at 11:50
still the same thing
– Akshay Shrivastav
Dec 30 '18 at 11:40
still the same thing
– Akshay Shrivastav
Dec 30 '18 at 11:40
what does console.log(obj) gives in console
– Shantanu Terang
Dec 30 '18 at 11:42
what does console.log(obj) gives in console
– Shantanu Terang
Dec 30 '18 at 11:42
(4) ["sdf", " da", " adf", " ad"] 0: "sdf" 1: " da" 2: " adf" 3: " ad" length: 4 __proto__: Array(0)
– Akshay Shrivastav
Dec 30 '18 at 11:50
(4) ["sdf", " da", " adf", " ad"] 0: "sdf" 1: " da" 2: " adf" 3: " ad" length: 4 __proto__: Array(0)
– Akshay Shrivastav
Dec 30 '18 at 11:50
one more error i spotted
Uncaught TypeError: f[b] is not a function at HTMLDivElement.<anonymous> (tagging.min.js:223) at Function.each (jquery-3.3.1.min.js:2) at w.fn.init.each (jquery-3.3.1.min.js:2) at w.fn.init.e.fn.tagging (tagging.min.js:220) at HTMLDocument.<anonymous> (post.js:149) at l (jquery-3.3.1.min.js:2) at c (jquery-3.3.1.min.js:2)
– Akshay Shrivastav
Dec 30 '18 at 11:50
one more error i spotted
Uncaught TypeError: f[b] is not a function at HTMLDivElement.<anonymous> (tagging.min.js:223) at Function.each (jquery-3.3.1.min.js:2) at w.fn.init.each (jquery-3.3.1.min.js:2) at w.fn.init.e.fn.tagging (tagging.min.js:220) at HTMLDocument.<anonymous> (post.js:149) at l (jquery-3.3.1.min.js:2) at c (jquery-3.3.1.min.js:2)
– Akshay Shrivastav
Dec 30 '18 at 11:50
add a comment |
You don't have to parse the tagger because it already in json format:
<script>
var tagger = <?php echo json_encode((array)$tags);?>;
$.each(tagger, function(key,value)
{
$("#post_tags").tagging("add", value);
});
</script>
i tried doing this, it gives the following errorUncaught TypeError: Cannot use 'in' operator to search for 'length' in ["sdf"," da"," adf"," ad"]
– Akshay Shrivastav
Dec 30 '18 at 11:36
try the edited answer
– McBern
Dec 30 '18 at 11:41
still the same error
– Akshay Shrivastav
Dec 30 '18 at 11:49
can you var_dump the $tags?
– McBern
Dec 30 '18 at 11:52
array (size=4) 0 => string 'sdf' (length=3) 1 => string ' da' (length=3) 2 => string ' adf' (length=4) 3 => string ' ad' (length=3)
– Akshay Shrivastav
Dec 30 '18 at 11:56
|
show 2 more comments
You don't have to parse the tagger because it already in json format:
<script>
var tagger = <?php echo json_encode((array)$tags);?>;
$.each(tagger, function(key,value)
{
$("#post_tags").tagging("add", value);
});
</script>
i tried doing this, it gives the following errorUncaught TypeError: Cannot use 'in' operator to search for 'length' in ["sdf"," da"," adf"," ad"]
– Akshay Shrivastav
Dec 30 '18 at 11:36
try the edited answer
– McBern
Dec 30 '18 at 11:41
still the same error
– Akshay Shrivastav
Dec 30 '18 at 11:49
can you var_dump the $tags?
– McBern
Dec 30 '18 at 11:52
array (size=4) 0 => string 'sdf' (length=3) 1 => string ' da' (length=3) 2 => string ' adf' (length=4) 3 => string ' ad' (length=3)
– Akshay Shrivastav
Dec 30 '18 at 11:56
|
show 2 more comments
You don't have to parse the tagger because it already in json format:
<script>
var tagger = <?php echo json_encode((array)$tags);?>;
$.each(tagger, function(key,value)
{
$("#post_tags").tagging("add", value);
});
</script>
You don't have to parse the tagger because it already in json format:
<script>
var tagger = <?php echo json_encode((array)$tags);?>;
$.each(tagger, function(key,value)
{
$("#post_tags").tagging("add", value);
});
</script>
edited Dec 30 '18 at 12:03
answered Dec 30 '18 at 11:34


McBernMcBern
520147
520147
i tried doing this, it gives the following errorUncaught TypeError: Cannot use 'in' operator to search for 'length' in ["sdf"," da"," adf"," ad"]
– Akshay Shrivastav
Dec 30 '18 at 11:36
try the edited answer
– McBern
Dec 30 '18 at 11:41
still the same error
– Akshay Shrivastav
Dec 30 '18 at 11:49
can you var_dump the $tags?
– McBern
Dec 30 '18 at 11:52
array (size=4) 0 => string 'sdf' (length=3) 1 => string ' da' (length=3) 2 => string ' adf' (length=4) 3 => string ' ad' (length=3)
– Akshay Shrivastav
Dec 30 '18 at 11:56
|
show 2 more comments
i tried doing this, it gives the following errorUncaught TypeError: Cannot use 'in' operator to search for 'length' in ["sdf"," da"," adf"," ad"]
– Akshay Shrivastav
Dec 30 '18 at 11:36
try the edited answer
– McBern
Dec 30 '18 at 11:41
still the same error
– Akshay Shrivastav
Dec 30 '18 at 11:49
can you var_dump the $tags?
– McBern
Dec 30 '18 at 11:52
array (size=4) 0 => string 'sdf' (length=3) 1 => string ' da' (length=3) 2 => string ' adf' (length=4) 3 => string ' ad' (length=3)
– Akshay Shrivastav
Dec 30 '18 at 11:56
i tried doing this, it gives the following error
Uncaught TypeError: Cannot use 'in' operator to search for 'length' in ["sdf"," da"," adf"," ad"]
– Akshay Shrivastav
Dec 30 '18 at 11:36
i tried doing this, it gives the following error
Uncaught TypeError: Cannot use 'in' operator to search for 'length' in ["sdf"," da"," adf"," ad"]
– Akshay Shrivastav
Dec 30 '18 at 11:36
try the edited answer
– McBern
Dec 30 '18 at 11:41
try the edited answer
– McBern
Dec 30 '18 at 11:41
still the same error
– Akshay Shrivastav
Dec 30 '18 at 11:49
still the same error
– Akshay Shrivastav
Dec 30 '18 at 11:49
can you var_dump the $tags?
– McBern
Dec 30 '18 at 11:52
can you var_dump the $tags?
– McBern
Dec 30 '18 at 11:52
array (size=4) 0 => string 'sdf' (length=3) 1 => string ' da' (length=3) 2 => string ' adf' (length=4) 3 => string ' ad' (length=3)
– Akshay Shrivastav
Dec 30 '18 at 11:56
array (size=4) 0 => string 'sdf' (length=3) 1 => string ' da' (length=3) 2 => string ' adf' (length=4) 3 => string ' ad' (length=3)
– Akshay Shrivastav
Dec 30 '18 at 11:56
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53977209%2fparsing-json-values-through-jquery-is-eliminating-1st-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
962 A,D2OysqU2ylpzl5xbxcIu1 2cemhkxzl6UY,fVHG0G,o4AFeJc,63SMmpLEiuWXCxZR