2021年3月13日星期六

Symfony v2.8 Response( $message ) method 'returning' more than expected

My goal is to return a message to my web-page, where it is to be displayed, but instead of just the message, the value returned contains the message and html code for an error page!

I am using the following code to return a message result to an ajax call:

Server-Side PHP code that is called by an Ajax call ...

$message = 'Some message to be displayed.';    // Return to the page and display the message ...    return new Response( $message );  // Inspecting $message shows only                                    // 'Some message to be displayed.'  

Client-Side JavaScript code that calls the above code and receives the response:

$.ajax( { // Send form data to the same page that the page came from            type:        'POST',            data:        data,            cache:       false,            async:       true,            contentType: false,            enctype:     'multipart/form-data',            processData: false          } )  .done( function( data, textStatus, jqXHR ) { ... }  .fail( function( jqXHR, textStatus, errorThrown ) { ... } // Inspecting jqXHR                                                            // shows more than                                                            // 'Some ...  

When breakpoints are set at the return new Response( $message ); and first executable line in the .done(...) function, the PHP script execution gets to the breakpoint at the return new Response( $message ); statement without any errors and I can see that the parameter's value is 'Some message to be displayed.', as expected, but when paused at the .done() function's first line, the data parameter's value is: Some message to be 'displayed.<!DOCTYPE html><html>...</html>!

Where, if the html code is placed in a file and loaded into the browser it looks somewhat like this:

Whoops, looks like something went wrong.  1/1 FatalErrorException in debug-eval(1) : eval()'d code line 1:  Parse Error: syntax error, unexpected ')'  in debug-eval(1) : eval()'d code line 1  

An obvious error message, but my code isn't using any eval() statements that could fail and the execution got to the Response statement without any errors. Is this a bug in the Symfony Response statement method/function? If not, how can I find out what is really happening, so I can fix it?

Thank you

https://stackoverflow.com/questions/66620701/symfony-v2-8-response-message-method-returning-more-than-expected March 14, 2021 at 11:05AM

没有评论:

发表评论