Welcome Guest, Not a member yet? Register   Sign In
jQuery, Add / Delete elements without page refresh
#11

[eluser]Chris Newton[/eluser]
Yes, the script tag is called immediately above the jquery delete script. It looks like the forum stripped out the script tags, so it makes it a bit confusing.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;title&gt;test&lt;/title&gt;
    <scri+pt src="&lt;?=base_url()?&gt;scripts/jquery-1.2.1.js" ></scri+pt>
    
    
    <scri+pt languge="javascript" type="text/javascript">
    $('.delete').click(function(){
    $.ajax({
       type: "POST",
       url: "/index.php/test_ajax_controller/delete",
       data: "id="+$(this).prev().text(),
       success: function(html){
           $("#show").html(html);
           }
    });
    return false
    });
    </scri+pt>
&lt;/head&gt;

&lt;body&gt;
<table>
<tr><td>filename</td><td>other info</td><td><span class="hidden">3</span>&lt;input type="submit" class="delete" value="delete"&gt;</tr>
</table>
<br />
<br />
<p>
<div id="show"></div>
</p>
&lt;/body&gt;
#12

[eluser]xwero[/eluser]
[quote author="mahuti" date="1194395902"]
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;title&gt;test&lt;/title&gt;
    <scri+pt src="&lt;?=base_url()?&gt;scripts/jquery-1.2.1.js" ></scri+pt>
    
    
    <scri+pt languge="javascript" type="text/javascript">
   $(function(){ // added
    $('.delete').click(function(){
    $.ajax({
       type: "POST",
       url: "/index.php/test_ajax_controller/delete",
       data: "id="+$(this).prev().text(),
       success: function(html){
           $("#show").html(html);
           }
    });

    return false
    });
    }); // added
    </scri+pt>
&lt;/head&gt;

&lt;body&gt;
<table>
<tr><td>filename</td><td>other info</td><td><span class="hidden">3</span>&lt;input type="submit" class="delete" value="delete"&gt;</tr>
</table>
<br />
<br />
<p>
<div id="show"></div>
</p>
&lt;/body&gt;
[/quote]
I've added 2 lines that should make it work.
#13

[eluser]Chris Newton[/eluser]
*sigh* omg.... you don't know how many different things I've thought of over the last week. That worked like a charm. It's ALWAYS the little things.

Thank you so much man! Awesome!
#14

[eluser]xwero[/eluser]
glad you got it working
#15

[eluser]jafarsalam[/eluser]
Thank you so much man! Awesome![/quote]

I'm new to php and found this could be helpfully to me. I would like to be able to display file names from a directory and be able to delete/download them.

any help would be appreciated.


jeff
#16

[eluser]Natebot[/eluser]
Jeff,

Codeigniter has got your back (as usual). Listing the files located in a directory is a snap.

Consult the user guide's section on the file helper
http://ellislab.com/codeigniter/user-gui...elper.html

Code:
get_filenames('path/to/directory/')

returns an array of file names. Just use a foreach loop to step through the array to create your list of links. Deleting them can be done like you did above with an ajax call to another controller method and pass the file's name. Just make sure you control where the script is unlinking files - you don't want the user deleting files elsewhere on your server!
#17

[eluser]jafarsalam[/eluser]
Hi Grad;

Wow,thanks for the quick reply.

is there a place where I can download the complete set of scripts scripts and uploaded it to my server .


thanks
jeff




Theme © iAndrew 2016 - Forum software by © MyBB