开发者

initialise external php file - javascript / jQuery

开发者 https://www.devze.com 2023-02-25 16:03 出处:网络
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 functi

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??

Thanks in advance... :)

blasteralfr开发者_C百科ed


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.
   });
});


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消