views:

59

answers:

2

I want to call an ajax function to do some stuff...

function RemoveTest(subfolder)
{
    var datastring="name="+subfolder;
    alert(datastring);
    $.ajax({
    type: "POST",
    url: "mystuff.php",
    data: datastring,
        success: function(msg){
           alert( "Data Saved: " + msg );
               // some suff there
        }
    }); 
}


<a href="javascript:void(0)" onclick="RemoveTest('test')">Click Me</a>

I am unable to use this please tell me how to do this.... and which jQuery file i have to include..

A: 

Just make

<a href="javascript:void(0)" onclick="RemoveTest('test')">Click Me</a>

to

<a id="link">Click Me</a>

and JS

$(document).ready(function(){
$("#link").click(fucntion(){
 var datastring="name="+subfolder;
    alert(datastring);
    $.ajax({
    type: "POST",
    url: "mystuff.php",
    data: datastring,
        success: function(msg){
           alert( "Data Saved: " + msg );
               // some suff there
        }
    })
});

});
Fincha
I have so many link that are dynamically created... so how to do this stuff..
Anil P
$("a").click and pass attribute "rel" on links with Folder Name, like <a href="" id="test" rel="FOlder">Click</a> or use Folder as ID of Link
Fincha
<a href='javascript:void(0);' onclick="MyTest()">Click me</a><script type="text/javascript">function MyTest() { //alert("test"); jQuery.ajax({ type: "GET", url: 'removelist.php', data: 'name=test', success: function(msg){ alert('success'); }, error: function(XMLHttpRequest, textStatus, errorThrown){ alert('error'); } }); }</script>This script always raise error on alert.. where is the proble. the file path is correct.
Anil P
A: 

If you are using any library other thanjQuery which uses $ then make sure that there is no conflict. See jQuery.noConflict(). Also make sure that you refer your jQuery file at the top before calling any jQuery functions.

Also if you want to create event handlers for dynamically crated anchor tags, then better give them a class name and a data attribute, something like

<a href='#' class='democlass' data-id='yourvalue'>Click me</a>

$("a.democlass").live("click", function(){
    var id = $(this).attr('data-id');
});
rahul