user10351273
user10351273

Reputation:

When I receive image path from database using ajax in codeigniter. it gives me error in the image path

When I receive image path from database using ajax in codeigniter. it gives me that error. This is the function from which the image is received from database.

public function master_get_employees()
    {
        if ($this->input->post()) { //If Any Values Posted
            if ($this->input->is_ajax_request()) { //If Request Generated From Ajax
                $ID = $this->input->post('ID');
                if (!isset($ID) || !is_numeric($ID)) {
                    echo "FAIL::Something went wrong with POST request, Please contact system administrator for further assistance::error";
                    return;
                }
                $table = "employees e";
                $selectData = "e.id AS ID,e.Picture as pic,e.IsEnabled";
                $where = array(
                    'e.id' => $ID, 'e.IsActive' => 1
                );
                $result = $this->Common_model->select_fields_where_like_join($table, $selectData, $where, TRUE);
                print json_encode($result);
            }
        }
    }

And the error is that. this is the error

Upvotes: 0

Views: 57

Answers (3)

Syed Waqas Ahmad
Syed Waqas Ahmad

Reputation: 134

Basically, the "json_encode" is added that forward slashes to the path you can replace this code

  print json_encode($result);

With This code

print json_encode($result,JSON_UNESCAPED_SLASHES);

Upvotes: 2

Rp9
Rp9

Reputation: 1963

PHP's json_encode, by default, escapes slashes.

You can override this by doing

json_encode($result, JSON_UNESCAPED_SLASHES);

Upvotes: 2

Asmaa3107
Asmaa3107

Reputation: 766

May it is stored wrong in db I mean you use "/" instead of "\" change it and see if it appears

or write a code on your frontend which replace "/" with "\" in coming image url .

Upvotes: 3

Related Questions