onclick="loadInlineEditor({
class:'<?= get_class($content) ?>',
model_id:<?= $content->id ?>,
attribute:'description'
})"
Output for get_class($content)
should be appmodelsPage
But Inside controller this appmodelsPage
is how I get it back via sending it as AJAX request
AJAX code:-
function loadInlineEditor(data) {
$.ajax({
url: '<?= Url::toRoute(["//url"]) ?>',
type: 'POST',
data: data,
dataType: 'json'
})
Output Code:-
Array
(
[class] => appmodelsPage
[model_id] => 1
[attribute] => description
)
2
Answers
It’s not ajax that is removing the slashes. It’s because the js code generated by php looks like this:
But
(backslash) character in JS string is used as escape char. If you want to use backslash in JS string you have to escape it by itself as
\
.To do that you can use either
addslashes()
php function orjson_encode()
.The
json_encode
will add the"
around the string so you don’t have to use quotes too.Because the **** was an escape characters so you need to escape it before store him in the class properties.
So your code become :
In fact the addslashes send appmodelsPage to the class properties and it save to appmodelsPage