How do you pass an apostrophe through a URL?

后端 未结 4 780
时光取名叫无心
时光取名叫无心 2020-12-29 03:43

I\'m using Node.js:

var s = \'Who\\\'s that girl?\';
var url = \'http://graph.facebook.com/?text=\' + encodeURIComponent(s);

request(url, POST, ...)
         


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-29 04:21

    I'm doing a similar thing (also with Node.js) and first tried using JavaScript's built-in escape() function, but it didn't really work.

    Here's how I ended up getting search to work. It might just be a fluke:

     function doMySearch(showTitle) {
         showTitle = escapeShowTitle(showTitle)
         var url = "http://graph.facebook.com/search?q=" + showTitle + "&type=page"
         doSomethingWith(url)
    }
    
    function escapeShowTitle(title) {
        title = title.replace(/'/g, "")
        title = escape(title)
        return title
    }
    
    doMySearch("America's Funniest home Videos")
    

提交回复
热议问题