Results 1 to 10 of 10

Thread: post/get through ajax troubles

  1. #1

    post/get through ajax troubles

    hey there kirupa gang, i have little troubles with a simple site; here's the diagram:



    Contents are placed in a div thru ajax; it works perfectly and parses php right but here's the catch, how do I use post and get with that div ?

    I use a standard contact.php page:
    -php checks if there's anything in 'post' (and validates) and
    -php displays a #mail sent# form if mailto() was success
    or
    -php displays a form to send a message which uses a 'post' action to itself (contact.php)

    Here's the catch:
    Since I load contact.php in the div thru ajax/dhtml I can't use standard 'submit' button or it refreshes the page with post but I have to use my ajax code. Now how do I transmit post ? (or get for that matter). It seems that my contact.php page gets its 'post' from the root (index.php)

    have I lost everyone ?

    I use the following xmlhttprequest:

    Code:
    function fetch(url, target) {
      document.getElementById(target).innerHTML = ' Fetching data...';
      if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      }
      if (req != undefined) {
        req.onreadystatechange = function() {fetchDone(url, target);};
        req.open("GET", url, true);
        req.send("");
      }
    }  
    
    function fetchDone(url, target) {
      if (req.readyState == 4) { // only if req is "loaded"
        if (req.status == 200) { // only if "OK"
          document.getElementById(target).innerHTML = req.responseText;
        } else {
          document.getElementById(target).innerHTML="Page Error:\n"+ req.status + "\n" +req.statusText;
        }
      }
    }
    
    function loadthis(name, div) {
    	fetch(name,div);
    	return false;
    }
    thanks to anyone who attempts to understand me

  2. #2
    biznuge's Avatar
    1,136
    posts
    Use the Fork Luke...
    use an "anchor" element and then set it's "onclick" attribute to call whatever javascript function you'd like... á la...

    HTML Code:
    <script language="javascript">
    function click(){
    alert("you clicked me!");
    }
    </script>
     
    <a href="javascript:void(0);" onClick="javascript:click();">click me</a>
    s'that whatcha meen???
    before you judge someone, you should walk a mile in their shoes. That way, when you judge them, you're a mile away, and you have their shoes...
    "A lack of planning on your part does not constitute an emergency on mine" - Danonthemoon
    She asked for a double entendre, so I gave her one...
    "screw ie. it can lick my balls" - A.J. Cates

  3. #3
    mmhmh I don't think so, what I need is to write new post or get to my xmlhttp request. AND to read from it as well to see if my mail function worked

  4. #4
    ^ No... what he means is that anchor is the submit button, meaning that the page then won't auto send to the form target. Then in a javascript function have the code to read the form inputs and then run an AJAX request with POST variables.

  5. #5
    biznuge's Avatar
    1,136
    posts
    Use the Fork Luke...
    ^ rgr that...

    Where i've put the alert in the "click" function, you could simply pick up your form values with a "document.getElementById" on the form elements, and then simply pass these values to your XMLHTTP request code, and subsequent request return.

    Or, I suppose if you wanted to, you could do this with an input element of type button, and set it's onclick event...

    s'up to you...
    Last edited by biznuge; January 30th, 2008 at 08:03 AM.
    before you judge someone, you should walk a mile in their shoes. That way, when you judge them, you're a mile away, and you have their shoes...
    "A lack of planning on your part does not constitute an emergency on mine" - Danonthemoon
    She asked for a double entendre, so I gave her one...
    "screw ie. it can lick my balls" - A.J. Cates

  6. #6
    Dude, use jQuery... it makes it sooo easy to post/get using ajax, and you can create custom functions for it too! Just check it out: http://www.jquery.com/

  7. #7
    I use jquery for my own website (you know, the forever in construction type) but I really want to do this one all by hand, and gain knowledge through it


    thanks for all your answers

    it's the "pass these values to your XMLHTTP request code" which bothers me now

  8. #8
    biznuge's Avatar
    1,136
    posts
    Use the Fork Luke...
    sorry mlk. no disrespect, but, to be honest, I'm currently taking a little look at jquery, since i seem to currently understand what the hell i'm doing with ajax (i think, just been to the pub so i may be wrong...) but i think you're going down the right road of trying to build this stuff yourself.

    if you wanna pm me (maybe msn) about this feel free, since i'm off work tomorrow, friday, and the weekend (family permitting) I may have some time to offer something.

    keep it up!
    before you judge someone, you should walk a mile in their shoes. That way, when you judge them, you're a mile away, and you have their shoes...
    "A lack of planning on your part does not constitute an emergency on mine" - Danonthemoon
    She asked for a double entendre, so I gave her one...
    "screw ie. it can lick my balls" - A.J. Cates

  9. #9
    haha I'd love to but I've got humongous work of 3d to do in the next couple of days, im just a php enthusiast !

    thanks (and nice geeky location btw, I remember it as CAH SOH TOA, in french it sounds like 'get the f### out' )

  10. #10
    biznuge's Avatar
    1,136
    posts
    Use the Fork Luke...
    lol @ my 500th post...
    before you judge someone, you should walk a mile in their shoes. That way, when you judge them, you're a mile away, and you have their shoes...
    "A lack of planning on your part does not constitute an emergency on mine" - Danonthemoon
    She asked for a double entendre, so I gave her one...
    "screw ie. it can lick my balls" - A.J. Cates

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012