Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have json data I'm having difficulty turning into a string. How can I format it so that it can become strings?
jsfiddle: http://jsfiddle.net/s97QX/2/
code:
Jsonvar = {"shows":[{"show_id":6387, "shownum":6387,"title":"The Protestant's Dilemma","guest":"Devin Rose","category":"Non-Catholic","url":"http://www.catholic.com/radio/shows/the-protestants-dilemma-11565","audiourl":"http://www.catholic.com/sites /default/files/audio/radioshows/ca140331b.mp3","datetime":"1396317600","description":"
Devin Rose <\/p>","thumbnailsmall":"http://www.catholic.com/sites/default/files/imagecache/profile_square_small/images/profilepics/a109aad8daa70ad8976ffc.L._V387899120_SX200_.jpg","thumbnaillarge":"http://www.catholic.com/sites/default/files/imagecache/profile_square_large/images/profilepics /a109aad8daa70ad8976ffc.L._V387899120_SX200_.jpg"}]};
var jsonstr=JSON.stringify(Jsonvar);
alert(jsonstr);
First You validate your json using jsonlint.
JSONLINT
then try.
This error in the console explains it:
Uncaught SyntaxError: Unexpected token ILLEGAL
You have a line break in your object:
Jsonvar = {"shows":[{"show_id":6387, "shownum":6387,"title":"The Protestant's Dilemma","guest":"Devin Rose","category":"Non-
Catholic","url":"http://www.catholic.com/radio/shows/the-protestants-dilemma-
11565","audiourl":"http://www.catholic.com/sites/default/files/audio/radioshows/ca140331b.mp3"
,"datetime":"1396317600","description":" <<<- Here
Devin Rose
Remove that and that property will become a valid string, therefore you'll be able to stringify it
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Here is the line of code I am trying to target: <img class="pi" src="/graphics/ni/ni90.jpg" alt="Awaiting image">
I'm trying to select all of the images that have the attribute alt="Awaiting image"
If I try document.querySelectorAll("img.pi");
I will get all of the images that have the class pi
If I try document.querySelectorAll("img.pi[alt="Awaiting image"]");
I will get the error:Uncaught SyntaxError: missing ) after argument list
What is it that I am missing here?
The " used to delimit the value in the attribute selector are clashing with the " used to delimit the JS string literal.
document.querySelectorAll("img.pi[alt="Awaiting image"]");
^ ^^
| |Error
| End of string
Start of string
Use a different kind of quote.
document.querySelectorAll('img.pi[alt="Awaiting image"]');
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Hi im pretty sure what im about to post might not be enough info (if so please let me know what more is needed). I am using node js and having a really weird error. Below is the code and output.
if (currentPrice > variableData[i].stopLossHard) {
console.log('if')
console.log(currentPrice)
console.log('is more than')
console.log(variableData[i].stoplossHard)
}
Output:
if
92.7
is more than
93.62700000000001
This is consistently happening. I also made sure that both currentPrice and variableData[i].stopLossHard are numbers and not strings (I made sure in the code and in the output its the color of a number not a string)
Any ideas is highly appreciated.
The attribute you print is different than the one you check in the if statement:
(In the if stopLossHard has a capital L, stop-L-ossHard, what you print doesn't)
Try this:
if (currentPrice > variableData[i].stoplossHard) {
console.log('if')
console.log(currentPrice)
console.log('is more than')
console.log(variableData[i].stoplossHard)
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Here is the button code:
<button class="ncss-btn-black fs16-sm ncss-brand pb3-sm pl5-sm pr5-sm pt3-sm mr3-sm u-uppercase css-1n4ymyz" data-test="qa-cart-checkout">Checkout</button>
I have tried the following;
document.querySelector("button[data-test='qa-cart-checkout']”).click();
But I get the following error;
Uncaught SyntaxError: Invalid or unexpected token
What am I doing wrong? Please help, thanks.
I need the answer in modern dom or jquery.
It works fine as long as you use "normal" single and double quotes, not backticks or "smart quotes":
document.querySelector("button[data-test='qa-cart-checkout']").click();
<button class="ncss-btn-black fs16-sm ncss-brand pb3-sm pl5-sm pr5-sm pt3-sm mr3-sm u-uppercase css-1n4ymyz" data-test="qa-cart-checkout" onclick="alert('it works')">Checkout</button>
In Javascript a Backtick means template literals.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
use regular ' or "
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
i have a objectId on my mvc model which i want to sent to a mvc API call, which results in a
"Uncaught SyntaxError: Invalid or unexpected token"
<script>
$(function () {
$('.btn-saveshedule').click(function () {
var selectedValue = $("#sel1 option:selected").val();
var userid =#Model.Id.ToString();
var json = getTimeSlotsInJson($('.schedule'), userid.str, selectedValue);
});
});
</script>
how on earth do i convert #Model.Id to a string?
You just need to put single quotes around it:
var userid ='#Model.Id.ToString()';
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
So, me and a few friends are making a text adventure in JavaScript. in it, there is a possibility of the player using a heal spell, which runs the following code:
function heal() {
alert('You chant some ominous-sounding words, and your wounds heal');
alert('Hit points restored!');
hitPoints += 60;
blobsOfDoom -= 30;
burn();
MonsAtt();
Choose Spell();
}
Error Messages:
Firefox:
/*
Exception: SyntaxError: missing ; before statement
#Scratchpad/1:2703
*/
Chrome:
SyntaxError: Unexpected identifier.
Why is this error showing up? How do I fix it?
You cant have spaces in functions
Choose Spell();
Check your function declaration for ChooseSpell and any other occurances, and change them to a valid function name, like chooseSpell()