why cant i put a var in a encodeURI?
why is this working?
var movieName = encodeURI("deadpool");
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + movieName;
and this not?; iven put a console log to check and that works
var movieName = $(".shown .title").html();
console.log(movieName);
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURI(movieName);
jquery var encodeuricomponent
add a comment |
why is this working?
var movieName = encodeURI("deadpool");
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + movieName;
and this not?; iven put a console log to check and that works
var movieName = $(".shown .title").html();
console.log(movieName);
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURI(movieName);
jquery var encodeuricomponent
I suspect the HTML has some extra whitespace around the name, try.html().trim()
to remove it.
– Barmar
Jan 2 at 23:22
BTW, you should useencodeURIComponent
, notencodeURI
. See stackoverflow.com/questions/4540753/…
– Barmar
Jan 2 at 23:22
In what way isn't it working? Can you show the output ofconsole.log(url)
?
– Barmar
Jan 2 at 23:31
api.themoviedb.org/3/search/…
– drunkgummyboy
Jan 2 at 23:34
That looks fine, what's the problem?
– Barmar
Jan 2 at 23:35
add a comment |
why is this working?
var movieName = encodeURI("deadpool");
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + movieName;
and this not?; iven put a console log to check and that works
var movieName = $(".shown .title").html();
console.log(movieName);
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURI(movieName);
jquery var encodeuricomponent
why is this working?
var movieName = encodeURI("deadpool");
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + movieName;
and this not?; iven put a console log to check and that works
var movieName = $(".shown .title").html();
console.log(movieName);
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURI(movieName);
jquery var encodeuricomponent
jquery var encodeuricomponent
asked Jan 2 at 23:18
drunkgummyboydrunkgummyboy
104
104
I suspect the HTML has some extra whitespace around the name, try.html().trim()
to remove it.
– Barmar
Jan 2 at 23:22
BTW, you should useencodeURIComponent
, notencodeURI
. See stackoverflow.com/questions/4540753/…
– Barmar
Jan 2 at 23:22
In what way isn't it working? Can you show the output ofconsole.log(url)
?
– Barmar
Jan 2 at 23:31
api.themoviedb.org/3/search/…
– drunkgummyboy
Jan 2 at 23:34
That looks fine, what's the problem?
– Barmar
Jan 2 at 23:35
add a comment |
I suspect the HTML has some extra whitespace around the name, try.html().trim()
to remove it.
– Barmar
Jan 2 at 23:22
BTW, you should useencodeURIComponent
, notencodeURI
. See stackoverflow.com/questions/4540753/…
– Barmar
Jan 2 at 23:22
In what way isn't it working? Can you show the output ofconsole.log(url)
?
– Barmar
Jan 2 at 23:31
api.themoviedb.org/3/search/…
– drunkgummyboy
Jan 2 at 23:34
That looks fine, what's the problem?
– Barmar
Jan 2 at 23:35
I suspect the HTML has some extra whitespace around the name, try
.html().trim()
to remove it.– Barmar
Jan 2 at 23:22
I suspect the HTML has some extra whitespace around the name, try
.html().trim()
to remove it.– Barmar
Jan 2 at 23:22
BTW, you should use
encodeURIComponent
, not encodeURI
. See stackoverflow.com/questions/4540753/…– Barmar
Jan 2 at 23:22
BTW, you should use
encodeURIComponent
, not encodeURI
. See stackoverflow.com/questions/4540753/…– Barmar
Jan 2 at 23:22
In what way isn't it working? Can you show the output of
console.log(url)
?– Barmar
Jan 2 at 23:31
In what way isn't it working? Can you show the output of
console.log(url)
?– Barmar
Jan 2 at 23:31
api.themoviedb.org/3/search/…
– drunkgummyboy
Jan 2 at 23:34
api.themoviedb.org/3/search/…
– drunkgummyboy
Jan 2 at 23:34
That looks fine, what's the problem?
– Barmar
Jan 2 at 23:35
That looks fine, what's the problem?
– Barmar
Jan 2 at 23:35
add a comment |
1 Answer
1
active
oldest
votes
The HTML may have whitespace around the title, which you need to remove.
var movieName = $(".shown .title").html().trim();
Also, you should probably use .text()
rather than .html()
, in case there are embedded HTML tags.
var apiKey = "key";
var movieName = encodeURIComponent("deadpool");
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + movieName;
console.log(url);
var movieName = $(".shown .title").html().trim();
console.log(movieName);
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURIComponent(movieName);
console.log(url);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="shown">
<div class="title">
deadpool
</div>
</div>
I tried it and it didn't work, and there are also no embedded items in the .title element. thanks anyway
– drunkgummyboy
Jan 2 at 23:28
If you're using jQuery$.get
, it's better to put the parameters in a data object rather than creating the query string by hand. It will encode everything properly.
– Barmar
Jan 2 at 23:30
I've added a snippet showing that both of them create the same URL.
– Barmar
Jan 2 at 23:35
var movieName = $(".shown .title").text().trim(); console.log(movieName); var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURI(movieName); console.log(url);
it is working with this code, thanks a lot
– drunkgummyboy
Jan 2 at 23:42
add a comment |
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%2f54014445%2fwhy-cant-i-put-a-var-in-a-encodeuri%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The HTML may have whitespace around the title, which you need to remove.
var movieName = $(".shown .title").html().trim();
Also, you should probably use .text()
rather than .html()
, in case there are embedded HTML tags.
var apiKey = "key";
var movieName = encodeURIComponent("deadpool");
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + movieName;
console.log(url);
var movieName = $(".shown .title").html().trim();
console.log(movieName);
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURIComponent(movieName);
console.log(url);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="shown">
<div class="title">
deadpool
</div>
</div>
I tried it and it didn't work, and there are also no embedded items in the .title element. thanks anyway
– drunkgummyboy
Jan 2 at 23:28
If you're using jQuery$.get
, it's better to put the parameters in a data object rather than creating the query string by hand. It will encode everything properly.
– Barmar
Jan 2 at 23:30
I've added a snippet showing that both of them create the same URL.
– Barmar
Jan 2 at 23:35
var movieName = $(".shown .title").text().trim(); console.log(movieName); var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURI(movieName); console.log(url);
it is working with this code, thanks a lot
– drunkgummyboy
Jan 2 at 23:42
add a comment |
The HTML may have whitespace around the title, which you need to remove.
var movieName = $(".shown .title").html().trim();
Also, you should probably use .text()
rather than .html()
, in case there are embedded HTML tags.
var apiKey = "key";
var movieName = encodeURIComponent("deadpool");
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + movieName;
console.log(url);
var movieName = $(".shown .title").html().trim();
console.log(movieName);
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURIComponent(movieName);
console.log(url);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="shown">
<div class="title">
deadpool
</div>
</div>
I tried it and it didn't work, and there are also no embedded items in the .title element. thanks anyway
– drunkgummyboy
Jan 2 at 23:28
If you're using jQuery$.get
, it's better to put the parameters in a data object rather than creating the query string by hand. It will encode everything properly.
– Barmar
Jan 2 at 23:30
I've added a snippet showing that both of them create the same URL.
– Barmar
Jan 2 at 23:35
var movieName = $(".shown .title").text().trim(); console.log(movieName); var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURI(movieName); console.log(url);
it is working with this code, thanks a lot
– drunkgummyboy
Jan 2 at 23:42
add a comment |
The HTML may have whitespace around the title, which you need to remove.
var movieName = $(".shown .title").html().trim();
Also, you should probably use .text()
rather than .html()
, in case there are embedded HTML tags.
var apiKey = "key";
var movieName = encodeURIComponent("deadpool");
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + movieName;
console.log(url);
var movieName = $(".shown .title").html().trim();
console.log(movieName);
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURIComponent(movieName);
console.log(url);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="shown">
<div class="title">
deadpool
</div>
</div>
The HTML may have whitespace around the title, which you need to remove.
var movieName = $(".shown .title").html().trim();
Also, you should probably use .text()
rather than .html()
, in case there are embedded HTML tags.
var apiKey = "key";
var movieName = encodeURIComponent("deadpool");
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + movieName;
console.log(url);
var movieName = $(".shown .title").html().trim();
console.log(movieName);
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURIComponent(movieName);
console.log(url);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="shown">
<div class="title">
deadpool
</div>
</div>
var apiKey = "key";
var movieName = encodeURIComponent("deadpool");
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + movieName;
console.log(url);
var movieName = $(".shown .title").html().trim();
console.log(movieName);
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURIComponent(movieName);
console.log(url);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="shown">
<div class="title">
deadpool
</div>
</div>
var apiKey = "key";
var movieName = encodeURIComponent("deadpool");
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + movieName;
console.log(url);
var movieName = $(".shown .title").html().trim();
console.log(movieName);
var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURIComponent(movieName);
console.log(url);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="shown">
<div class="title">
deadpool
</div>
</div>
edited Jan 2 at 23:43
answered Jan 2 at 23:24
BarmarBarmar
434k36259362
434k36259362
I tried it and it didn't work, and there are also no embedded items in the .title element. thanks anyway
– drunkgummyboy
Jan 2 at 23:28
If you're using jQuery$.get
, it's better to put the parameters in a data object rather than creating the query string by hand. It will encode everything properly.
– Barmar
Jan 2 at 23:30
I've added a snippet showing that both of them create the same URL.
– Barmar
Jan 2 at 23:35
var movieName = $(".shown .title").text().trim(); console.log(movieName); var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURI(movieName); console.log(url);
it is working with this code, thanks a lot
– drunkgummyboy
Jan 2 at 23:42
add a comment |
I tried it and it didn't work, and there are also no embedded items in the .title element. thanks anyway
– drunkgummyboy
Jan 2 at 23:28
If you're using jQuery$.get
, it's better to put the parameters in a data object rather than creating the query string by hand. It will encode everything properly.
– Barmar
Jan 2 at 23:30
I've added a snippet showing that both of them create the same URL.
– Barmar
Jan 2 at 23:35
var movieName = $(".shown .title").text().trim(); console.log(movieName); var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURI(movieName); console.log(url);
it is working with this code, thanks a lot
– drunkgummyboy
Jan 2 at 23:42
I tried it and it didn't work, and there are also no embedded items in the .title element. thanks anyway
– drunkgummyboy
Jan 2 at 23:28
I tried it and it didn't work, and there are also no embedded items in the .title element. thanks anyway
– drunkgummyboy
Jan 2 at 23:28
If you're using jQuery
$.get
, it's better to put the parameters in a data object rather than creating the query string by hand. It will encode everything properly.– Barmar
Jan 2 at 23:30
If you're using jQuery
$.get
, it's better to put the parameters in a data object rather than creating the query string by hand. It will encode everything properly.– Barmar
Jan 2 at 23:30
I've added a snippet showing that both of them create the same URL.
– Barmar
Jan 2 at 23:35
I've added a snippet showing that both of them create the same URL.
– Barmar
Jan 2 at 23:35
var movieName = $(".shown .title").text().trim(); console.log(movieName); var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURI(movieName); console.log(url);
it is working with this code, thanks a lot– drunkgummyboy
Jan 2 at 23:42
var movieName = $(".shown .title").text().trim(); console.log(movieName); var url = "https://api.themoviedb.org/3/search/movie?api_key=" + apiKey + "&query=" + encodeURI(movieName); console.log(url);
it is working with this code, thanks a lot– drunkgummyboy
Jan 2 at 23:42
add a comment |
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%2f54014445%2fwhy-cant-i-put-a-var-in-a-encodeuri%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
I suspect the HTML has some extra whitespace around the name, try
.html().trim()
to remove it.– Barmar
Jan 2 at 23:22
BTW, you should use
encodeURIComponent
, notencodeURI
. See stackoverflow.com/questions/4540753/…– Barmar
Jan 2 at 23:22
In what way isn't it working? Can you show the output of
console.log(url)
?– Barmar
Jan 2 at 23:31
api.themoviedb.org/3/search/…
– drunkgummyboy
Jan 2 at 23:34
That looks fine, what's the problem?
– Barmar
Jan 2 at 23:35