Question

Im using ajax to send data to a php file which executes a query to a database and returns a string.

When im going to print that string in some html object or an alert(), it prints with two line breaks before the string.

Please help me to find why this happens.

Here is the code im using for ajax

$.ajax({
        data: parameters,
        url: "components/file.php",
        type: "POST",
        success: function(response){
            $('#Obs').text(response)
            }
    });

When i look the textarea with the id:Obs there is the response with two line breaks before it.

and this is the php file

            $cod=$_POST['id'];
            $name=$_POST['name'];
            $obs=$_POST['obs'];
            $pg= pg_query("SELECT set_session('USER_ID', '".$usr."')");
            $cadena="UPDATE elemento_consolidado SET nombre = '$name', observaciones ='$obs' WHERE id_elemento = '$cod'";
            $string = new sql_pg($cadena,$conn);
            $action=$string->query();
            $succes=$query->verify($action);
            echo $succes;

This code works fine, but the only issue is the two line breaks when i print the response of this php file.

If someone can help thank you! Greetings!

Sorry if my english is rustic.

Was it helpful?

Solution

Well, i find the solution, thank you @Natulysses.

Looking deeper in the internet I found someone with the same issue, and the solution is just check the php files which the ajax request is using. In my case the line-breaks were at the end of the file after the php closer('?>').

And if in the files theres no line-breaks Firebug should help to find the issue.

Thank you again and hope this question help somebody later.

Srry about answer so late...

Greetings!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top