1

I just built a web site by using this script:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
function loadpage(page)
{
    document.getElementById("pageContent").innerHTML="Yükleniyor...";
    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("pageContent").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET",page,true);
    xmlhttp.send();
}
</script>

It can load any page thanks to AJAX. But yet there is a question: when I load any page containing any HTML form, when i click "submit", it leaves the main page, I mean I can't send form variables by AJAX. the only thing I need is to pass form variables by using "href" and the loadpage() function I mentioned above.

How can I do get form input's values and send to another PHP file?

Ferdinand.kraft
  • 11,809
  • 7
  • 42
  • 67
  • So your goal is essentially to submit your form via AJAX? If so, you'll find [this answer](http://stackoverflow.com/questions/1960240/jquery-ajax-submit-form) helpful. – FThompson Sep 08 '13 at 18:57

2 Answers2

0

you can use jQuery.

$(document).ready(function(){
    $("#div_load").load("page.html");
});

whit this code you can open any page (Ex: page.html) in any div(Ex:div whit id=div_load).

and for sending data use it:

$(".class_div").click(function(){
    $.post("ajax.php",
    {
      name:"naser",
      age:"23"

    },
    function(data,status){
        // do something when done
    });
});
naser
  • 171
  • 2
  • 11
  • can you tell me just how to call my pageload() function like this -> [link]onclick=pageload('register2.php?nick=...&email=....')[/link] it is already passing variables when i write the link manually, the only thing i need is, to get variables from form inputs and use them in my url. – riza mahsuni Sep 08 '13 at 19:22
-1

As you are using jQuery, you can do:

$('form').submit(funciton() {
  var data = $(this).serialize();
  // Call Ajax
  return false;
});

I advice you to read about: http://api.jquery.com/category/ajax/ and http://api.jquery.com/serialize/.

Alex
  • 1,516
  • 9
  • 13