admin管理员组文章数量:1392073
I'm using the wikipedia and Google APis.
When I select a city, I want to display the page from wikipedia. I have some problems on putting the city variable in wiki search url.
The city is in myVariable var.
**var myVariable = locality;**
$.ajax({
type: "GET",
url: ".php?action=parse
&format=json&prop=text§ion=0&page= + myVariable + &callback=?",
I know that in javascript we make the concatenation with + but I guess I'm doing something wrong there and I can't figure out what.
I'm using the wikipedia and Google APis.
When I select a city, I want to display the page from wikipedia. I have some problems on putting the city variable in wiki search url.
The city is in myVariable var.
**var myVariable = locality;**
$.ajax({
type: "GET",
url: "http://en.wikipedia/w/api.php?action=parse
&format=json&prop=text§ion=0&page= + myVariable + &callback=?",
I know that in javascript we make the concatenation with + but I guess I'm doing something wrong there and I can't figure out what.
Share Improve this question edited Feb 24, 2015 at 20:20 crixi asked Feb 24, 2015 at 20:19 crixicrixi 1592 gold badges4 silver badges12 bronze badges 3-
1
What do you think
" + foo + "
does? What about" ++++ foo ++++ "
? – Felix Kling Commented Feb 24, 2015 at 20:22 - 2 You could use the technique called "debugging". Instead of sitting around staring at your code and wondering why it doesn't work, or wasting other people's time, in "debugging" you actually do things yourself to figure out why it doesn't work. For instance, you could assign the url string you are creating to a variable, and then examine it in a debugger. If you don't know what that is, find out right away before you code another line. This has the advantage that you can actually solve your own problems instead of having to post to SO every time. – user663031 Commented Feb 24, 2015 at 20:25
- 1 ^ developer.mozilla/en-US/docs/Debugging_JavaScript – Felix Kling Commented Feb 24, 2015 at 20:25
2 Answers
Reset to default 2Try this.
url: "http://en.wikipedia/w/api.php?action=parse&format=json&prop=text§ion=0&page=" + myVariable + "&callback=?"
Do this...
url: "http://en.wikipedia/w/api.php?action=parse
&format=json&prop=text§ion=0&page=" + myVariable + "&callback=?"
本文标签: javascriptConcatenate a variable in a urlStack Overflow
版权声明:本文标题:javascript - Concatenate a variable in a url - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744767741a2624144.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论