why cant i put a var in a encodeURI?












0















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);









share|improve this question























  • 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













  • 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
















0















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);









share|improve this question























  • 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













  • 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














0












0








0








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);









share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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











  • 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











  • 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











  • 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












1 Answer
1






active

oldest

votes


















0














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>








share|improve this answer


























  • 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














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
});


}
});














draft saved

draft discarded


















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









0














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>








share|improve this answer


























  • 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


















0














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>








share|improve this answer


























  • 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
















0












0








0







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>








share|improve this answer















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>






share|improve this answer














share|improve this answer



share|improve this answer








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





















  • 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






















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

A Topological Invariant for $pi_3(U(n))$