使用JavaScript去除斜线?可能的 [英] Use JavaScript to stripslashes ? possible

查看:88
本文介绍了使用JavaScript去除斜线?可能的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ajax来获取URL.问题在于URL中包含斜杠,并且在JQuery加载后单词后,它将不会加载页面.

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: function(data) {
 $('#OPTcontentpanel').load(data.OPTpermalink);

PHP

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

和响应

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

因此需要去除斜线.我知道如何用PHP做到这一点,但不知道如何使用 AJAX JavaScript.

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

有什么想法吗?

奇妙

推荐答案

一个旧问题的新答案:

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

使用示例:

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

输出:

You're slashed /\../\

这篇关于使用JavaScript去除斜线?可能的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆