A.B.Developer A.B.Developer - 2 years ago 108
Javascript Question

Datatables remove backslash(\) characters from data

This is my codes to use Datatables jquery plugin that send data via Ajax to server:

processing: true,
serverSide: true,
"bSort": false,
"responsive": true,
ajax: {
url: 'http://lms.dev/admin/getFilesList',
data: function (d) {
d.id = '8',
d.type = 'App\Lesson'
columns: [
{data: 'checkbox', name: 'checkbox', "width": "20px"},
{data: 'picture', name: 'picture', 'className': 'text-center'}

As you see,
parameter sent to server is contain a
(backslash) character. but when I retrive it in the laravel backend backslash character is removed.

What is Problem and why that is removed?

Answer Source

JavaScript has the \ as an escape character. You might need to use \\ to escape it. Change your code to:

d.type = 'App\\Lesson'

In the console itself, you can see how JavaScript treats \ and \\:

enter image description here

If the whole thing is generated by PHP, you may try using PHP's function addslashes() to generate string friendly output.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download