I'm writing Analytical software that uses javascript but mainly PHP to log things
The javascript posts some result to $_GET variable like this
document.location.href = "?screenwidth=" + screen.width + "&screenheight=" + screen.height; but this requires the page to reload for PHP to process it.
However the page CANNOT reload every time someone visits, because it disrupts the user experience too much.
Is there a way, in javascript or PHP, of opening dynamically the PHP file, not in an iframe, cos that messes up the formatting, so PHP can operate on it and write it to a MYSQL database.
I don't mind if this requires some complicated code - I'm hapy to give it a bash.
You could send all this data via an asynchronous post request using javascript (AJAX). I'd recommend using one the frameworks such as jquery, they make this very simple.
You could send all this data via an asynchronous post request using javascript (AJAX). I'd recommend using one the frameworks such as jquery, they make this very simple.
How would I do this? Is it possible without reloading the page?
so, ajax is powerfull, but easy to hack, so i do not recommand ajax for such things.
What an absolutely nonsense statement. AJAX is just a technique used to send a request to the server, just the same as if you typed the url and hit enter yourself. Your solution of opening another window with a form which the user then has to submit anyway is far, far less graceful than sending the request automatically, and precisely no more secure.
What an absolutely nonsense statement. AJAX is just a technique used to send a request to the server, just the same as if you typed the url and hit enter yourself. Your solution of opening another window with a form which the user then has to submit anyway is far, far less graceful than sending the request automatically, and precisely no more secure.
hi there =)
first, i want to scream out, that my daughter was born on 2009-06-02 23:15:00 and we named her 'michelle' =) and yes, i'm proud bout this little girl XD
so to this quote you should read something more on some official sites =)
$.post(
"stats.php", // script which saves stats
{
// the data to send
foo: "someValue",
bar: 123,
baz: "some other value" // etc
},
function(response) {
// callback function from your php script
alert(response.message);
},
"json" // response format
);
stats.php:
PHP Code:
<?php
if (!isset($_POST)) die();
// save the stats or whatever here, they are all in $_POST, eg $_POST['foo'] == "someValue"
// send a response if you want to echo json_encode(array('message' => 'Hooray! You sent: ' . print_r($_POST, true)));
All well and good until you want to use something other than a transitional doctype, not to mention the annoying click every time the iframe refreshes. Plus this will resend the stats every 5 mins, surely you want stats once per request? There is really no need to be using iframes in this day and age!
Saying AJAX is responsible for security holes is utter rubbish. If the code requested has security holes, it makes no difference whether AJAX is involved or not. AJAX is just a technique, not a technology in itself. But you carry on using JS popups like it's 1998, it's no skin off my nose!
You are really not going about this the right way. There is a technique designed for doing just what you are trying to do already. Please don't be put off by some of the rubbish posted in this thread.
If you wrote your html and css properly you wouldn't need to worry about the client's screen dimensions. What are you going to do for people with javascript disabled.
If you wrote your html and css properly you wouldn't need to worry about the client's screen dimensions. What are you going to do for people with javascript disabled.
If you'll excuse me saying, I'm a web designer and I think I know how to write CSS and (X)HTML. As Mindzai correctly pointed out, I am writing an analytics package for distribution (free) and, although this is not something I require, Screen Resolution is something logged by Google Analytics, the most well-known free package. Many people may take this into account when considering using my software.
For people without javascript, the main script runs in php, so that will pick most things up. Please do not flame, it is considered offensive on forums. The iframe was a temporary method of implementing javascript.
To connect javascript and PHP, it is necessary either to set cookies or to compose a url using javascript. Both require a page reload for PHP to interpret them. This messes up detection of the referrer in PHP, so I used an iframe.
I repeat on sending a url of a PHP script for the image, how do I get it do display the image?
Thanks,
Ronnie268
Failure isn't an option - It comes bundled with Windows
π ~= 3.14
3*14 = 42
Coincidence? I think not.
π = The Answer to Life, the Universe, and Everything.
Bookmarks