AJAX request and PHP class functions

后端 未结 8 866
小鲜肉
小鲜肉 2020-12-08 05:29

How to call a PHP class function from an ajax call

animal.php file

class animal
{     
  function getName()
  {
    return \"lion\";
  }         


        
8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 05:47

    Can you please mention which are you using any Framework? You method is correct but I want to mention two things over here. First try your URL from the browser and check if its working correctly. Secondly don't use return, in *success: function(data) * data will contain only the output. so use Echo rather then return

提交回复
热议问题