1

I have a div with id trigger in my page. I have a php file action.php which will delete contents in my text file mytext.txt. I want to do that when I click trigger using jQuery. Or is there any function to do that without PHP file?

2 Answers 2

1

You can bind a click handler to your DIV. It's actually better if you had a link instead, but not essential (i.e. - html5)

$('#trigger').click(function(){
   $.get('action.php', {}, function(data){ //populate {} if you want to send any data
      alert(data);//whatever your action.php file echoes out.
   });
});
Sign up to request clarification or add additional context in comments.

Comments

1

Using $.ajax, you can call your PHP script from Javascript.. You can't access neither client-side nor server-side files (such as mytext.txt) from javascript.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.