-5

Is there any way I can call a PHP function from jQuery? I have a .js file and a .php file.

I have a jQuery event applied on a button click. Now I want to set a condition on what happens next when the button is clicked depending on whether a user is logged in or not. Is there any way I can do this from my .js file ?

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328

3 Answers3

0

You can call any php file by the common HTTP methods, e.g. GET and POST. What you might be looking for is AJAX. Google the term, and also look into jQuery for a simplified approach.

Zsolt Szilagyi
  • 4,741
  • 4
  • 28
  • 44
0

You can send it to a php file with ajax and use your php file to check if the user's logged in. Then you can send a response back to your js file to see which event you should trigger

Sjoerd de Wit
  • 2,353
  • 5
  • 26
  • 45
0

Technically, yes. But why would you want to in this case? My suggestion is to look into storing values in cookies, since both PHP and JS will have access to them.

Community
  • 1
  • 1
Nicholas Summers
  • 4,444
  • 4
  • 19
  • 35