-1

I currently have this

destDiv.append("<td><a href="+value.FileLocation+">Download Here</a></td>") 

But I actually want to url encode the value.filelocation to my download script getsonginfo.php

7
  • 2
    So use encodeURIComponent and encode it? developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Aug 27, 2014 at 15:08
  • 1
    Here comes the answer train. Did you try researching "url encode value javascript"? Commented Aug 27, 2014 at 15:09
  • possible duplicate of How to encode URL in JavaScript and PHP? Commented Aug 27, 2014 at 15:09
  • Thanks for all the sarcasm, its really helpful. of course i researched, struggled for an hour then asked a question. :D Commented Aug 27, 2014 at 15:29
  • It wasn't sarcastic, it was a question. I typed the exact phrase above into Stack Overflow search and found an answer, so I wondered if you had tried that. Commented Aug 27, 2014 at 15:37

1 Answer 1

0

If I am understanding your question correctly, all you want to do is the following:

destDiv.append("<td><a href='getsonginfo.php?url="+encodeURIComponent(value.FileLocation)+"'>Download Here</a></td>") 

The encodeURIComponent will handle encoding the value.FileLocation correctly, and the href needs a ' around it so that it's properly parsed (otherwise the encodeURIComponent is pointless).

Sign up to request clarification or add additional context in comments.

6 Comments

Where'd you get getsonginfo.php?url= from? 0_o
And, where did you get the idea that it needs a single quote around it? Not true.
@DJDavid98 "to my download script getsonginfo.php" the url= part was improvisation on my part, but working in PHP that's the most likely construction.
@Chris Either single or double quote, but without it certain strings will get encoded incorrectly which actually is only relevant if the FileLocation can contain user content.
The statement is simply incorrect. The function call to encodeURIComponent is not aware of the context it is being called from. It doesn't know if you're concatenating it into a string, setting it as a element property, logging to console... it doesn't know or care. It does what it does, using a single quote in your HTML does not impact that in the slightest.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.