I have got "localhost/management".
I have got my site for customers: "localhost/website".
So I got 2 websites (one for management, one for customers).
Now I have made a javascript which causes to show a popup onload.
The javascript is included into the customer side.
Now what I need to do is make an HTTP request from my javascript to the management side
(which is connected to database) and get a value from that.
So when a value is (1 - show popup at customer side) (0 - not show popup at customer side).
The value has to come from the database.
When I'm at the management side and when I made some changes (like updating info) then the value has to change too.
I'm working with localhost.
Asked
Active
Viewed 83 times
0
Jbadminton
- 2,055
- 3
- 22
- 45
-
2You don't make a 'PHP' request in JavaScript, you make an **http** request. – roberrrt-s Dec 19 '16 at 08:53
-
allright, how do i do that? – Jbadminton Dec 19 '16 at 08:54
-
using JavaScript AJAX ... communication possible. – Soni Vimalkumar Dec 19 '16 at 08:54
-
I dont know exactly how to use it. – Jbadminton Dec 19 '16 at 08:58
-
I guess what you need is a tutorial. – Beginner Dec 19 '16 at 08:59
-
Who will set that value (0/1) to database? is that someone from management? Can someone from management will be able to edit that setting (0 to 1 or 1 to 0)? – toothful Dec 19 '16 at 09:04
-
@SelimMahmud Yes exactly :) – Jbadminton Dec 19 '16 at 09:06
-
Is your javascript in a separate js file or somewhere in html page? – toothful Dec 19 '16 at 09:08
-
separate javascript file and when I include the file, it must work for that page. – Jbadminton Dec 19 '16 at 09:10
-
As stated [AJAX](http://www.w3schools.com/xml/ajax_intro.asp) is what you need. Roughly described: AJAX is a way for JavaScript to pretend a "pageload" on a specific url and return the result (if any). With it you can send data to your server (and by extension to PHP) and return whatever response results from it. – Emil S. Jørgensen Dec 19 '16 at 09:29
-
Yeah I know but I don't know how to use that !! – Jbadminton Dec 19 '16 at 09:31
-
I linked to W3Schools AJAX tutorial: http://www.w3schools.com/xml/ajax_intro.asp. Here is a tutorial that takes you through the JavaScript process: https://www.youtube.com/watch?v=qqRiDlm-SnY – Emil S. Jørgensen Dec 19 '16 at 09:39
-
if you can put your javascript code inside the page, may be somewhere in footer or in the body, you do not need any ajax to do that. Using PHP you can connect to management database and get that setting value (0 or 1) and then use if state to add javascript if the value is 1. – toothful Dec 19 '16 at 09:40
-
@SelimMahmud it must work independent of which site you are, any website should use this and only need to include the js file to work, so i can't put the js code inside the page – Jbadminton Dec 19 '16 at 09:43
-
OK... You probably are building a javascript plugin. Then you can probably introduce some initialization code with possible setting so that whoever use that javascript file, have to initialize with that setting value. – toothful Dec 19 '16 at 09:56
-
This is what I have now: http://codepen.io/anon/pen/aBXyYW – Jbadminton Dec 19 '16 at 10:08