Hi,pleasure to meet you all.I wanna to ask how to write a javascript code to connect with php api authentication located at my server(eg. www.mydomain.com/api/index.php).


1.I wanna put a javascript code to call the api authentication function at my website server so that other people can access through the api key provide by my website.
eg location script www.mydomain.com/api/script/access.js

2.the access.js will call to my server's api(www.mydomain.com/api/index.php),do the authenticate api process and return the result back to client side(if not valid api key,don't allow return result data to the client side.

3.so, how do i write the javascript code to put at www.mydomain.com/api/script/access.js(this script need to call the api key authentication class that located at my server)?is that i can use the cookies of the client side to detect again the user data when the user next time access the access.js?

4. how to i write the api key authentication class at my www.mydomain.com/api/index.php so that only valid api key user can access the result data?

Note:www.mydomain.com/api/script/access.js can be access through embeded into html format like this

<script src="www.mydomain.com/api/script/access.js?key=ADD_YOUR_KEY_HERE" type="text/javascript"></script>

Note:Kindly give simple code so that i can more understandable on the flow.
Note:thanks for all guys help solve my problem!!!:)

Is that only can do using ajax way? i m sorry to say that i havnt create any api communication between php and javascript before!what i want is create a js scipt(this scipt can be access by other web site developer with valid api key) to communicate with the php file to let authenticate user retrieve/create/update the data to the database through the script .

Only way JS and any server language is via AJAX. I cannot see any other way!

i m sorry to say that i havnt create any api communication between php and javascript before! .

Check w3Schools

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.