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
Here’s what our current JavaScript equivalent to PHP's stripslashes looks like. You you can install via npm install locutus and require it via require ('locutus/php/strings/stripslashes') . You could also require the strings module in full so that you could access strings.stripslashes instead.
stripslashes (string $string): string Un-quotes a quoted string. stripslashes () can be used if you aren't inserting this data into a place (such as a database) that requires escaping. For example, if you're simply outputting data straight from an HTML form.
After several hours I found that stripslashes () made the string longer and hence it wasn't "equal" for the query. This code shows the behavior (copy into "test.php"). Replacing stripslashes worked for me. Rather use str_replace than explode/implode for your purpose. A replacement that should be safe on utf-8 strings.
stripslashes () is not recursive. If you want to apply this function to a multi-dimensional array, you need to use a recursive function. $value = is_array($value) ? Array ( [0] => f'oo [1] => b'ar [2] => Array ( [0] => fo'o [1] => b'ar ) )
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 /\../\
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With