ok i mite have to do that. i’ll look it up and get back to u. thanks!
phdr,
I tried to implement something i found on w3schools, but i’m not seeing the confirm dialog popup. can you give me a push? here’s what i’ve got:
< script >
function emptyReport() {
if (confirm(‘Are you sure you want to clear the report data?’)) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open(“GET”, "deletereportdata.php?);
xmlhttp.send();
//reload the page to show that the report data has been cleared
alert( 'Report data has been cleared! You will now only see visitor information from this point on.' );
header( "Refresh:0" );
} else {
}
}
< /script >
Perhaps if you edit your post and use either bbcode [code][/code]
tags or the forum’s preformatted text </> menu button, so that the code will appear as is and can be read?
` <script>`
`function emptyReport() {`
`if (confirm(‘Are you sure you want to clear the report data?’)) {`
`var xmlhttp = new XMLHttpRequest();`
`xmlhttp.open(“GET”, "deletereportdata.php);`
`xmlhttp.send();`
` //reload the page to show that the report data has been cleared`
` alert( 'Report data has been cleared! You will now only see visitor information from this point on.' );`
` header( "Refresh:0" );`
` } else {`
` }`
`}`
`</script>`
hey, I don’t think the < / > option on this forum works man. everytime I push that button when I have the code highlighted, it only puts single quote marks around the first line. I had to highlight each line at a time in that last post to get the code to appear on the page properly. is this a bug on this forum?
i might be in the wrong place, phdr. the code i posted is js and this is a PHP forum. so I don’t expect u to respond. sorry about that.
The <input ...
line from your first post and the last posted javascript (after undoing the forum’s ‘publishing’ alterations - [code][/code]
tags would have been a better choice to use) works for me. What does your browser’s developer console say?
BTW - you should use a post method request when performing an action on the server, such as creating, updating, or deleting data. This is so that a search engine indexing your site won’t cause unexpected changes.
there are “?” marks around the CONFIRM() function and the GET() method in PHP. see image I’ve posted:
Those are smart/curly-quotes, the result of ‘publishing’ code. You must delete and re-type them as straight, plain, ascii quotes.
ok man, here’s what I have:
<script>
function emptyReport() {
if (confirm('Are you sure you want to clear the report data?')) {
var xmlhttp = new XMLHttpRequest ();
xmlhttp.open("GET", "deletereportdata.php");
xmlhttp.send();
alert('Report data has been cleared! You will now only see visitor information from this point on.');
header("Refresh:0");
}
}
</script>
the dialogs are working perfectly now, however the page is not reloading even with the “header()” function in there. isn’t header() a PHP function though? if I include “?” tags around that line and go to the page, it reloads constantly and won’t stop. which of course makes good sense, as i realize that php is executed before anything else like u said.
Header is a PHP function, it is not a Javascript function however. PHP doesn’t do refresh.
sorry for the late reply, astone. how exactly would I make the page reload itself with PHP then? I got the code from my last post thru a goog search.
I don’t see the point of using Ajax if you want the page to refresh, that is the entire point of using ajax. If that’s what you want to do, just have the page submit and it will cause it to reload by default.
You can use javascript for a refresh, however.
location.reload();
as in SUMBIT, you mean like the following without any value in the METHOD arg?
<button type="submit">
then clicking the button will simply refresh the page ur saying?
Well the method type attribute for the form is still needed to the backend knows how to process the message. But, yes. If you just submit the form, it will do the refresh on it’s own.
Maybe I am misunderstanding what you want? Are you just looking to clear fields? Or does it also need to do something on the backend as well?
this is just a simple-stupid traffic report for a small business man. so what i’ve done is echoe’d out all the database data that’s captured on every page of his website for every visitor. I’ve filtered the queries though with a WHERE clause so he doesn’t see all the bot visits from the various companies that do that crap.
so I’ve got a 5 column HTML table and PHP echo’s out all the data in it, and above the table I’ve got a plain button that says “clear report”. when he clicks it, what it should do is throw the data that’s in the table to a new table where the rest of the prior historical traffic data is stored, delete the table data, show a javascript message that tells him he’s starting fresh, then reload the page to show a blank screen that tells him there’s no records to show.
I had it working at one point, but somehow screwed it up. I have the js code to show the message, but when I put PHP tags around the DELETE statement in SQL, the js alert function before the tags does not execute , nor does the confirm() function that appears before the tags.
Okay, so there is backend processing that needs to run then.
I would still tackle this in a non-ajax version. let the button do its’ default behavior, it will hit the php script for doing all that processing, causing the truncated table to be fetched with not data, and the process restarts.
i will test it and get back to you. I never did think that AJAX was needed for this, but someone who obviously was mistaken told me differently. thanks!
LOL, no one told you to do anything. The suggestion was based on what the posted code was trying to do, use onclick to call a javascript function that you expected to perform an operation on the server, and was given as a “perhaps” choice, i.e. used to express uncertainty or possibility.
When you were doing research on what AJAX was, what did you learn that caused you to choose to use it?
If you want to just use html, you need a post method form that submits to the same page all this code is on and when submitted causes the DELETE form processing code to be executed. The form processing code must detect that a post method request was made, detect what operation to perform (use a hidden field in the form, named action for example, with the value ‘delete’), enforce user permissions to insure that the current visitor is authorized to perform a DELETE operation, then execute the code/query(ies) needed to accomplish the operation. When the form processing code has successfully completed, you should do a header() redirect to the exact same URL of the page to cause a get request for that page - Post Redirect Get (PRG.). This will cause the process to start anew.
the directory in which this report is at is protected by a godaddy directory level permissions setting. so that’s how I took care of that issue. I’ll try what you’ve mentioned and post back here when I’ve tried it. it might be a little while. thank you very much you guys. I learned quite a bit from what you’ve said.