Use JavaScript to stripslashes ? possible

RIK picture RIK · Mar 16, 2011 · Viewed 34.3k times · Source

I'm using ajax to grab a URL. The problem is the URL has slashes in it and when the JQuery load takes place afterwords it will not load the page.

AJAX success bit:

success: function(data) {
 $('#OPTcontentpanel').load(data.OPTpermalink);

PHP

echo json_encode( array('OPTpermalink'=>$OPTpermalink,));

AND the response

http:\/\/www.divethegap.com\/update\/options\/padi-open-water\/

So need to strip the slashes. I know how to do it in PHP but not in AJAX JavaScript.

Any ideas?

Marvellous

Answer

ColBeseder picture ColBeseder · Jan 31, 2013

A new answer to an old question:

String.prototype.stripSlashes = function(){
    return this.replace(/\\(.)/mg, "$1");
}

Example of use:

var str = "You\'re slashed \/\\..\/\\"; // Text from server
str = str.stripSlashes() ;

output:

You're slashed /\../\