jQuery AJAX callbacks

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>
Hi all,
I’m trying to handle file upload with JQuery AJAX, and upload succeeds. Problem is that I don’t understand how to deal with the success, error callbacks. I already tried to json_encode an array containing the ‘error’ and ‘success’ key, but result.success stays undefined…
What are the parameters result, textStatus, jqXHR standing for? Is the result parameter delivered by the (in my case) server script?
If anyone can provide good and clear resources on this topic, many thanks!!!

Zeff.

```

jQuery.ajax(’/ci.php/admin/handle_image_upload/’, {
method: ‘post’,
processData: false,
contentType: false,
data: formData,

		success: function(result, textStatus, jqXHR)
		{
			console.log(JSON.stringify(result));
			
			if(typeof result.error === 'undefined')
			{
			    // Success so call function to process the form
			    console.log('SUCCESS: ' + result.success);
			}
			else
			{
			    // Handle errors here
			    console.log('ERRORS: ' + result.error);
			}
		},
		error: function(jqXHR, textStatus, errorThrown)
		{
			// Handle errors here
			console.log('ERRORS: ' + textStatus);
		},
		complete: function()
		{
			// STOP LOADING SPINNER
			$('#loading-img').hide();
		}

	});
<do not remove the three backticks above>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.