adding a php function into javascript
I have a file for a calendar made with javascript called calendar_db.js, in it there is this if statment:
if (d_current.getDay() != 3 && d_current.getDay() != 6)
a_class[a_class.length] = 'availab开发者_如何学Pythonle';
it checks if the day is not the 3d or the 6th then. So my question is how to make a php mysql query to get those numbers (3 and 6) because I want to change them with mysql databse. What are your suggestions?
Thank you for your time and help.
The short answer is: You can't
However, you can use Ajax (Google it) to make calls to an external php file, which will process your request for you. Then, the php file can print out the result, which will send the information back to you.
Take a look here: http://www.w3schools.com/ajax/default.asp
EDIT:
Read the javascript file by using fopen(), file_get_contents(), or CURL:
http://www.php-mysql-tutorial.com/wikis/php-tutorial/reading-a-remote-file-using-php.aspx
Use some kind of regex to parse the javascript file looking for the particular match of the line with your values. If your javascript file isn't going to change much, it might be easier to just count lines and characters and get the number at exactly some position. This assumes your numbers will always be single digits.
Is this what you're after?
You have to use AJAX to interact with the server via JavaScript.
Since the code to setup an AJAX request is a bit long and tedious, I'll show you how to do it with the jQuery framework.
Basically, just make the server spit the two values out (imagine this being the output of foo.php):
12,19
Now, with AJAX you can read that output. There are two types of requests: GET
and POST
. If you're familiar with PHP, you can change this according to what your application uses:
var day1, day2;
$.get('foo.php', function(data) {
var split = data.split(',');
day1 = parseInt(split[0]);
day2 = parseInt(split[1]);
});
Now day1
and day2
hold your two dates.
精彩评论