Jon Wilson
Jon Wilson

Reputation: 75

Executing a php file onClick

I currently have a php file executing:

<a href="test.php?foo=boo">test</a>

I would rather not have to load a new page and do it onClick.

Does anyone know a simple way to do this?

I added a more complete example, including the suggested ajax. I still am having trouble getting it it to work though.

<script type="text/javascript">
    $('li').click(function() {
    $.ajax({ type: "GET", url: "test.php", data: { foo: 'boo' }, success: function(data){
          // use this if you want to process the returned data
         alert('complete, returned:' + data);
    }});
    });
</script>
</head>
<body>
    <div id="header">
    <h1>Title</h1>
    </div>      
    <ul>
        <li><a href="#">Test</a></li>
    </ul>
</body>
</html>

Upvotes: 4

Views: 6002

Answers (3)

Olical
Olical

Reputation: 41352

Yes, as your tags say. You will need to use AJAX.

For example:

$.ajax({
    type: "GET",
    url: "test.php",
    data: "foo=boo"
});

Then you just have to stick that within a click function.

$('a').click(function() {
    // The previous function here...
});

EDIT: Changed the method to GET.

Upvotes: 5

Poonam Bhatt
Poonam Bhatt

Reputation: 10302

In your firl say e.g try.html write this code

<meta http-equiv="refresh" content="2;url=test.php?foo=boo"> 

it will redirect u to test.php?foo=boo in 2 seconds

OR Other way ===========================================

create one php file

<?php
header('Location: test.php?foo=boo');
exit;
?>

Hope this help

Upvotes: -4

oezi
oezi

Reputation: 51797

you could use jquery and do something like this:

$.ajax({ url: "test.php", data: { foo: 'boo' }, success: function(data){
      // use this if you want to process the returned data
      // alert('complete, returned:' + data);
    }});

for more information, take a look at the jquery-documentation

Upvotes: 5

Related Questions