Debugging a PHP file called by jQuery

Asked
Active3 hr before
Viewed126 times

6 Answers

90%

I'm using uploadify (a jQuery uploading) script, which has basically a PHP file at the backend. I want to do some kind of debugging of PHP code, (for example see what kind of errors I get in the PHP file (when it's called by jQuery), but I don't know how I can print the errors. For example the original PHP file is:,When this PHP file is called by the script, it won't go to the next line but it wont print the message either. How can I print the error message? If it can't be done this way, can I display some javascript alert message. The idea is to know where the error in the PHP file is. Thanks.,if your using apache server get httpd.conf file and search for ErrorLog log location and open the log file you will have proper error message to debug the issue.,[EDIT:] According this page http://www.uploadify.com/forums/discussion/2085/built-in-debug/p1 Uploadify doesn't come with a debug mode. So you are better writing in a log file with file_put_contents Also this flash works like a normal HTML form (except that flash can retrieve a percentage of uploading), so you can create a simple HTML form thant send a file through your PHP such as:

You can do it like this:

$("#fileUpload").fileUpload({
   ...
   'onComplete': function(a, b, c, data, e) {
      alert(data);
   }
});
load more v
88%

I'm using uploadify (a jQuery uploading) script, which has basically a PHP file at the backend. I want to do some kind of debugging of PHP code, (for example see what kind of errors I get in the PHP file (when it's called by jQuery), but I don't know how I can print the errors. For example the original PHP file is:,You can setup uploadify using jQuery .each(). This will allow you to set an id to be passed through the formData like this:,Try this in your INDEX.PHP file at the top to see what you are actually doing there .. My guess is it's the wrong path ... ,This is typically because you are not passing the correct header back to the browser. If you send (just before calling json_encode)

I'm using uploadify (a jQuery uploading) script, which has basically a PHP file at the backend. I want to do some kind of debugging of PHP code, (for example see what kind of errors I get in the PHP file (when it's called by jQuery), but I don't know how I can print the errors. For example the original PHP file is:

< ? php
if (!empty($_FILES)) {
   $tempFile = $_FILES['Filedata']['tmp_name'];
   $targetPath = $_SERVER['DOCUMENT_ROOT'].$_GET['folder'].
   '/';
   $targetFile = str_replace('//', '/', $targetPath).$_FILES['Filedata']['name'];
   move_uploaded_file($tempFile, $targetFile);
} ?
>

Now for example I add a line before move_uploaded_file() in the above code.

die("die befor moving file");

Here's the front end uploading page code:

<script type="text/javascript">

$(document).ready(function() {
    $("#fileUpload").fileUpload({
        'uploader': 'uploadify/uploader.swf',
        'cancelImg': 'uploadify/cancel.png',
        'script': 'uploadify/upload.php',
        'folder': 'files',
        'multi': false,
        'displayData': 'speed'
    });

});

</script>
</head>

<body>
    <fieldset style="border: 1px solid #CDCDCD; padding: 8px; ">
        <legend><strong>Uploadify Sample</strong></legend>
        <h2>Single File Upload</h2>
        <p>Display speed</p>
        <div id="fileUpload">You have a problem with your javascript</div>
    </fieldset>
</body>
</html>
load more v
72%

Once started, we can place breakpoints in JavaScript code and use the JavaScript debugger.,We can then place PHP breakpoints in the php file, and set JavaScript breakpoints in the js file.,Once the configuration is created, you can start the JavaScript debugging session from the PhpStorm toolbar:,Currently, setting both PHP and JavaScript breakpoints in one file is not supported. For example, no JavaScript breakpoints can be set in the following code:

Launch the JavaScript and PHP debugger at the same time

In the previous steps, we started the JavaScript and PHP debugger separately. When using Xdebug, we can pass a XDEBUG_SESSION_START URL parameter to our server to start PHP debugging simultaneously with JavaScript debugging. We can do this using a customized run/debug configuration. Create the run/debug configuration as you've done earlier, and make sure to append the XDEBUG_SESSION_START=some-session-name URL parameter, for example, ?XDEBUG_SESSION_START=phpstorm:

XDEBUG_SESSION_START
load more v
65%

I have a link on my post edit page (admin side) that calls up AJAX and jQuery to run a function inside my functions.php page. The link is wired up and calling the jQuery but I can't seem to debug whats going on inside my function thats being called from jQuery. I want the clicked link to delete custom metadata for the post (it is a custom post type) and then delete a file. ,Using FireBug all I see is for a response is 0. What is the best way to debug what is happening inside my function delete_pdf_and_metadata() being called via jQuery?,Connect and share knowledge within a single location that is structured and easy to search.,Also, it kinda looks like you expect an ID to come back from your AJAX call. You will need to echo that in the delete_pdf_and_metadata function, or build a JSON object and echo that.

I use the following to catch things that FireBug doesn't:

function print_log($msg, $title = '') {
   $error_dir = '/Applications/MAMP/logs/my.log';
   // or
   // $error_dir = '/home/user/public_html/wp-content/mu-plugins/my.log';
   $date = date('d.m.Y h:i:s'); // not used in this function
   $msg = print_r($msg, true);
   $log = $title.
   "  |  ".$msg.
   "\n";
   error_log($log, 3, $error_dir);
}
load more v
75%

Type debug(car.funcY) in the console and the script will stop in debug mode when it gets a function call to car.funcY:,In the Chrome console, you can keep an eye on specific functions. Every time the function is called, it will be logged with the values that it was passed in.,We've put together a list of 16 debugging tips that you may not know, but might want to keep in mind for next time you find yourself needing to debug your JavaScript code!,Most of these tips are for Chrome and Firefox, although many will also work with other inspectors.

if (thisThing) {
   debugger;
}
load more v
40%

// Assuming you are wishing to log to the JS Console...

<?php
	function consoleLog($msg) {
		echo '<script type="text/javascript">' .
          'console.log(' . $msg . ');</script>';
	}

	consoleLog('Hello, console!');
?>
load more v

Other "undefined-undefined" queries related to "Debugging a PHP file called by jQuery"