Single Quotes in String With Jquery Ajax

Single quotes in string with jQuery ajax

You could find one of the many String.replaceAll implementations or write your own, and just replace any single or double quotes with an escaped version like \" or \'.

How to remove double,single quotes from string and how to pass in ajax call

You have two choice:

Escape

You can escape double quotes by back slash like this:

$review_title = "New \"home\" away from home when in village";console.log($review_title);

to replace or remove double,single quotes from string in php/jquery

Use str.replace(/"|'/g,''); to remove double or single quotes:

var str = `New "home" away from home when in village's`;var res = str.replace(/"|'/g,'');console.log(res);

how to handle single quote in $.ajax POST (JQuery)?

Chetan is right on—jQuery handles that for you. But, it's worth mentioning the JavaScript escape() function, which is pretty simple:

>>> "O'Malley"
"O'Malley"
>>> escape("O'Malley")
"O%27Malley"

escaping single quotes for ajax calls

The problem is that $value contains single quotes, which interfere with the correct parsing of javascript. from the manual entry for html entities:

all characters which have HTML character entity equivalents are translated into these entities.

this means that your single quotes are not escaped, they are only translated in a way browsers will better understand. You need to use addslashes():

$value  = htmlentities(addslashes($DB_result->cloumn));

"'hello'" will become "\'hello\'" which in the browser will look like:

<input type = "button" onClick = "$('#something').val('\'hello\'');" />

which will attribute the string 'hello' (with the single quotes) to the value attribute of $('#something')



Related Topics



Leave a reply



Submit