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
Display Data Label (Legend) in Line-Chart Using Chartjs
Multi Select Drop Down With Checkbox
Remove Parameter from Url Via Regex
How to Get a File() or Blob() from an Url in JavaScript
Is It Okay to Call Onclick on an Anchor Tag in Reactjs
How to Count Duplicate Value in an Array in JavaScript
How to Set the Multi Sliders in One Page
How to Translate the Following Jquery Code to React
How to Add Data Dynamically to Mat-Table Datasource
The Onclick Is Not Working on First Click
Bootstrap Datepicker Appearing At Incorrect Location in a Modal
How to Convert Date Format from Dd.Mm.Yyyy to Dd/Mm/Yyyy in JavaScript
Copy/Paste from Excel to a Web Page
How to Validate for Only CSV File Uploads Using the Pattern Attribute Using Html5
Mongodb, Update Collection Field If New Value Is Not Null
How to Get Multiple Comma Separated Values from Url