SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    May 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calling a php file using a button

    Very, very early learning days

    I am displaying a number of buttons in a table.

    "<button type=\"button\" onclick=\"\">Add Event</button>" ;

    How do I call a php file addevent.php (which will contain an update form)

    http://www.spwg.ascribemeaning.com/lists/index.php is where I am playing.

  2. #2
    SitePoint Evangelist speda1's Avatar
    Join Date
    Jan 2002
    Posts
    550
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use the onclick event to call a javascript function that makes an Ajax call to a server side php function.

  3. #3
    SitePoint Member
    Join Date
    May 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for coming back.

    I have worked through
    AJAX Create an XMLHttpRequest Object
    to try and understand how AJAX works.

    I thought that I had my code right to satisfy the clicking of the 'Add Event' button (http://www.spwg.ascribemeaning.com/lists/) but I have missed something along the way. Am I on the right track? Could you please tell me where I am going wrong.

    (If index.php reads addevent.php then a big fat 'GOTCHA!' is supposed todisplay - see (http://www.spwg.ascribemeaning.com/lists/addevent.php)

    Many Thanks
    Ian

    My code is as follows:-

    <html>
    <head>
    <!--- Create XMLHttpRequest Oject using function in Head --->
    <script type="text/javascript">
    function addevent() // Changed from loadXMLDoc() to addevent()
    {
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
    }
    xmlhttp.open("GET","http://www.spwg.ascribemeaning.com/lists/addevent.php?t=",true);
    xmlhttp.send();
    }
    //xmlhttp.open("GET","ajax_info.txt",true); // http://www.spwg.ascribemeaning.com/lists/addevent.php
    // Sends request to Server "demo_get.asp?t=" - add a unique ID to the URL

    function myFunction()
    {
    //loadXMLDoc("ajax_info.txt",function()
    loadXMLDoc("http://www.spwg.ascribemeaning.com/lists/addevent.php?t=",function()
    {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
    });
    }

    </script>
    </head>

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    The best source for learning ajax seems to be the Bulletproof Ajax book, which also gives you free code and examples to learn from..
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Member
    Join Date
    May 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for that. I have ordered the book from Amazon and expect delivery early June.
    Meanwhile it is a dark, miserable, cold, wet, unseasonal Bank Holiday Monday in the UK, ideal for programming. Please could someone help me out with my code.
    Thanks Guys
    Ian

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Do what? View Post
    Please could someone help me out with my code.
    My pumpkin will be here shortly as it's nearing midnight, but you can check out the fully working sample code from the HTML—People part of Chapter 4, which is purposefully designed to be a fully working example of how to use Ajax to read HTML content and use it to update a section of the page.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •