Jump to content

Philip

Staff Alumni
  • Posts

    4,665
  • Joined

  • Last visited

  • Days Won

    20

Everything posted by Philip

  1. You're going to need to know Javascript. Here's a good spot to start: http://www.phpfreaks.com/forums/index.php/topic,115581.0.html Check out Ajaxfreaks,com for more tutorials/info
  2. <p align="center"> why is that there? You have it like this: <div><p><font></font></div><p><img></p> Where is the 2nd </p>, it should be before the div bolded above?
  3. Philip

    Logo

    Favicon Read up on it here: Wikipedia's explination
  4. Okay, then here: <input type="button" value="Delete" id="sendButton" onClick="confirmit();" /> Change it to <a href="delete.php" onClick="confirmit(); return false">linkie</a> Are you getting the variable from the URL to view the page where you have the option to delete? (viewitem.php?ID=1 -> it must be ID because of [var ID = gup(ID);])
  5. Have you started with any AJAX yet? Why not look at this one: question that is almost the same, just solved That should get you started, read through it, try it out, and come back with questions
  6. lol, nice. yeah, you could do that. Eventually, to save some space within your code, you can use what I did and do a switch, where you would give it like "confirmit(delete)" and then it would do a switch case off of what it was, in this case it would go through the deletion steps. However, that gets a little confusing/messy, so stick with the basics, but keep it in mind later on as you get better (and more comfortable) Don't forget to mark it solved if you think it was fixed
  7. In the PHP file check to see where the referrer ($_SERVER['HTTP_REFERER']) is coming from. If it's the correct IP/domain, then allow it, if not reject it.
  8. How is that possible? lol var t = gup(t); var f = gup(f); var url = "delete.php?f=" + f + "t=" + t; Well, maybe switch them here to where it goes: var url = "delete.php?f=" + t + "t=" + f; But, really, solve, not band-aid it Are they correct on the first page (where the JS gets the variables)?
  9. Why not just include it with the onClick();? Like: <a href="backifnojs.html" onclick="getID(link1)" id="link1">link 1</a> <a href="backifnojs2.html" onclick="getID(link2)" id="link2">link 2</a> Thats just how I would do it.
  10. Ahh, yeah. I tend to have a few typos =P Well, what do you mean they are the wrong way around? You mean like it should be: delete.php?t=$f&f=$t ?
  11. Okay, also in your PHP script, you need to have some way for AJAX to know if the deletion went through, a simple 1/0 will do fine. I'm not sure if this is causing the problem or not. <? include 'db.php'; $id = $_GET['t']; $f = $_GET['f']; $deletepost = mysql_query("DELETE FROM topics WHERE id = '$id' and fid = '$f' LIMIT 1"); $delpos = mysql_query($deletepost); if($delpos) { echo '0' // no error } else { echo '1' // error } ?>
  12. Okay I found the problem. The function I found earlier that got the URL parameter, wasn't working properly. I replaced it with another one, and I tested the following script (which works): <html> <head> <script type="text/javascript"> function createXMLHttp() { if (typeof XMLHttpRequest != 'undefined') return new XMLHttpRequest(); else if (window.ActiveXObject) { var avers = ["Microsoft.XmlHttp", "MSXML2.XmlHttp", "MSXML2.XmlHttp.3.0", "MSXML2.XmlHttp.4.0", "MSXML2.XmlHttp.5.0"]; for (var i = avers.length -1; i >= 0; i--) { try { httpObj = new ActiveXObject(avers[i]); return httpObj; } catch(e) {} } } throw new Error('XMLHttp (AJAX) not supported'); } var request = createXMLHttp(); function gup(strParamName){ var strReturn = ""; var strHref = window.location.href; if ( strHref.indexOf("?") > -1 ){ var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase(); var aQueryString = strQueryString.split("&"); for ( var iParam = 0; iParam < aQueryString.length; iParam++ ) { if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ) { var aParam = aQueryString[iParam].split("="); strReturn = aParam[1]; break; } } } return strReturn; } function sendRequest(request, url) { request.open("GET", url + '&GUINum=' + Math.floor(Math.random()*99999999999999999), true); // The math random is for IE to not cache it request.onreadystatechange = finishUpdate; request.send(null); } function confirmit() { input_box=confirm("Are you sure you want to delete this item?"); if (input_box==true) { var t = gup('f'); var f = gup('t'); var url = "delete.php?f=" + f + "t=" + t; alert(url); // Should display "delete.php?...." sendRequest(request, url); } else { //Abort part (I changed the text on page displaying 'aborted!' // Does not have to be anything } } function finishUpdate() { if (request.readyState == 4) { if (request.status == 200) { //do whatever when PHP script is done //perhaps refresh the page //or change the text on the page. whatever you want } } } </script> </head> <body> <a href="#" onclick="confirmit(); return false">delete me</a> </body> </html>
  13. <script type="text/javascript"> function createXMLHttp() { if (typeof XMLHttpRequest != 'undefined') return new XMLHttpRequest(); else if (window.ActiveXObject) { var avers = ["Microsoft.XmlHttp", "MSXML2.XmlHttp", "MSXML2.XmlHttp.3.0", "MSXML2.XmlHttp.4.0", "MSXML2.XmlHttp.5.0"]; for (var i = avers.length -1; i >= 0; i--) { try { httpObj = new ActiveXObject(avers[i]); return httpObj; } catch(e) {} } } throw new Error('XMLHttp (AJAX) not supported'); } var request = createXMLHttp(); function gup(name) { name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^]*)"; var regex = new RegExp( regexS ); var results = regex.exec( window.location.href ); if( results == null ) return ""; else return results[1]; } function sendRequest(request, url) { request.open("GET", url + '&GUINum=' + Math.floor(Math.random()*99999999999999999), true); // The math random is for IE to not cache it request.onreadystatechange = finishUpdate; request.send(null); } function confirmit() { input_box=confirm("Are you sure you want to delete this item?"); if (input_box==true) { var t = gup(t); var f = gup(f); var url = "delete.php?f=" + f + "t=" + t; alert(url); // Should display "delete.php?...." sendRequest(request, url); } else { //Abort part (I changed the text on page displaying 'aborted!' // Does not have to be anything } } function finishUpdate() { if (request.readyState == 4) { if (request.status == 200) { //do whatever when PHP script is done //perhaps refresh the page //or change the text on the page. whatever you want } } } </script> Make sure the script is the same as above. It should alert at least "delete.php?t=" on it
  14. Okay 2 things, Does it actually delete it from the DB? What does the alert show?
  15. Okay, lets do some troubleshooting: add in this right before sendRequest(request,url); alert(url); Also, you have this right after the AJAX request is made: var t = gup(t); var f = gup(f); var url = "delete.php?f=" + f + "t=" + t; function sendRequest(request, url) { .. Go ahead and delete it, you'll only need it when you run confirmit
  16. Okay: <input type="button" value="Delete" id="sendButton" onClick="confirmit();" /> And for within the JS: function confirmit() { input_box=confirm("Are you sure you want to delete this item?"); if (input_box==true) { var t = gup(t); var f = gup(f); var url = "delete.php?f=" + f + "t=" + t; sendRequest(request, url) } else { //Abort part (I changed the text on page displaying 'aborted!' } }
  17. You're not going to need to change gup at all. It does all the work for you. All you have to do is tell it what variable name you want to get out of the URL (which is where the gup(t) comes into play) For example: The url is /viewthread.php?t=100&f=999 In JS: var t = gup(t); // t becomes 100, if the url above is used var f = gup(f); // f becomes 999, if the url above is used
  18. Okay, since JS doesn't give any easy way (that I know of) to get variables from the URL, I've found a function that can do it. http://www.netlobo.com/url_query_string_javascript.html (and there are some disadvantages, read the comments) function gup( name ) { name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^]*)"; var regex = new RegExp( regexS ); var results = regex.exec( window.location.href ); if( results == null ) return ""; else return results[1]; } You would then put this into the JS and make t and f run the function: var t = gup(t); var f = gup(f); var url = "delete.php?f=" + f + "t=" + t; sendRequest(request, url); ... Does that make sense?
  19. Okay, what are you making the users do to select which one they want to delete? It does not have to be a full path.
  20. Use it in GET instead of POST in your JS. Here's a sample of some of my coding that you can change up: function createXMLHttp() { if (typeof XMLHttpRequest != 'undefined') return new XMLHttpRequest(); else if (window.ActiveXObject) { var avers = ["Microsoft.XmlHttp", "MSXML2.XmlHttp", "MSXML2.XmlHttp.3.0", "MSXML2.XmlHttp.4.0", "MSXML2.XmlHttp.5.0"]; for (var i = avers.length -1; i >= 0; i--) { try { httpObj = new ActiveXObject(avers[i]); return httpObj; } catch(e) {} } } throw new Error('XMLHttp (AJAX) not supported'); } var request = createXMLHttp(); function sendRequest(request, url) { request.open("GET", url + '&GUINum=' + Math.floor(Math.random()*99999999999999999), true); // The math random is for IE to not cache it request.onreadystatechange = finishUpdate; request.send(null); } function confirmit() { input_box=confirm("Are you sure you want to delete this item?"); if (input_box==true) { textr = "Deleting..."; var t = document.getElementById("t_value_box").value; var f = document.getElementById("f_value_box").value; var url = "delete.php?f=" + f + "t=" + t; sendRequest(request, url) } else { //Abort part (I changed the text on page displaying 'aborted!' } } function finishUpdate() { if (request.readyState == 4) { if (request.status == 200) { //do whatever when PHP script is done } } } That should be a good start for you, as it was for me with my AJAX script.
  21. This means you're missing a closing parenthesis in your script. Any other JS on the page?
  22. Like r-it said, yahoo has too many requests, that's why it freezes. Depending on the size of your site where ajax will be placed, the physical size of your application(s) (how big the script is), and the amount of usage the script(s) will get, will all play a factor into how long the loading will take. I doubt that you're going to have to worry about freezing. I might not have too much AJAX experience under my belt, but I do know a few things about it after playing around with it for a few weeks. It takes a lot of trial and error, especially if you haven't done much JS programming (like myself, I was strictly html/css/php, and didn't really believe in js since users can easily disable it.) You're going to find that IE can be a complete, well, pain in the ass, to deal with. Your script might work fine on other browsers, but then you'll get one that won't work. For me, it was IE, and still like 70% of the internet users use IE. Use a stat program, and see what percentage of users are using what browsers, then program off of that. Use that browser the most to do testing, but still test the others every now and then to make sure its still okay in them too. It will pay off in the long run, trust me. I thought I was done with it all, then I would go to IE and see nothing worked the way I wanted it to. Sorry for the long post, hopefully it helped. And as always, remember: Don't be afraid to ask questions!
  23. Yeah, it alerts a statement like above (just different variables inside each section) Edit: I found the problem. I had originally put in a [1] at the end, but it got deleted (I think when I was testing to see if it was getting the string correctly) so that's why it was showing the whole array. I need more sleep. Haha
  24. Hey guys, I'm not sure if it's because I'm using some AJAX, but I'll go ahead and post it here. I've been having some problems slitting a string (the response from my php script). My php page will echo a string like "1|0|40|titlehere". Then I have JS split the string by "|". However, when I try to print out one of the array parts it just comes back as "1,0,40,titlehere" var response1 = request.responseText.toString(); var response = response1.split("|"); var type = response[0]; var fail = response[1]; var title_id = response[2]; var title_name = response[3]; var fail_error = response[4]; var updatestatus = document.getElementById("update-status"); replaceText(updatestatus, response[2]); The code above should show a "0" for a string like "1|0|40|titlehere". Instead it shows "1,0,40,titlehere". I've tried just about everything I could do, adding split directly onto the response text, adding toString() (to make it reads it correctly), splitting again for the commas (which just gives js a loop, and it never finishes loading) Any ideas?
  25. Did the solved button disappear, or are my eyes going bad? I wouldn't be surprised if my eyes are dying... again.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.