Jump to content

Recommended Posts

I made a page to see if files are missing or available. I am using fancybox to bring up the form to upload a file. What I want is when the file is uploaded the "X" image on the page to be replaced with a check mark image without reloading the page.

 

Any help would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/265337-change-x-image-on-upload-of-file/
Share on other sites

(this needs moved to 3rd party scripts)

 

depending on what type of data you are requesting, you'll need to set a function on the javascript.  it's likely already there, you just don't know how to use it. refer to the plugin's docs to figure it out. Here's an example so you can zero in.

 

<?php
$response = array();  // prep data
if( !$upload  )  // file failed to upload
{ 						
$response = array(
	'status' 	=>	0,
	'msg'		=>	'File failed to upload',
)
} else {  // file uploaded just fine
$response = array(
	'status' 	=>	1,
	'msg'		=>	'Avatar has been updated!',
);
}
return json_encode($response);

 

...
dataType: 'json',
success: function (j) { // define the function object
if(j.status == true) {
	$('.response'). html('check');  // define the image response span
	$('.callback').removeClass('fail').addClass('success').html(j.msg);  // set appropriate CSS class and message
}else{
	$('.response').html('X');
	$('.callback').removeClass('success').addClass('fail').html(j.msg);
}
}
....

 

You need to set up your upload script (php) to pass the fail / success information back to the requestor (javascript).  the success function(j) sets the value of $response to j, which you can parse by using the key values, ie j.msg and j.status

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.