I have this script in ajax and is used to pass the value chosen by the user in the combo box to php. This also handles the submit button.
AJAX:
<script>
function loadXMLDoc(usertype) {
var value = $('#usertype').val();
var page='checksignup.php?usertype='+usertype;
document.location.href=page;
}
$( "#register_Chairperson" ).submit(function( event ) {
var usertype = $('#usertype').val();
alert(usertype);
loadXMLDoc(usertype);
event.preventDefault();
});
</script>
And I'm using this php code to get the value pass by ajax. But my problem is that nothing happens. My address became only like this: http://localhost/civil-engineering-dept/checksignup.php?usertype=1
. It did not continue in checking for the form for signing up. What do you think is the problem?
PHP:
$user = $_GET["usertype"];
And I'm using this php code to get the value pass by ajax.
That's not ajax, it looks like an attempt to load the XML in the browser window. To actually do that, change document
to window
and lose the href
.
window.location=page;
To actually use ajax, you'd use $.ajax
or $.get
(since you're trying to do a GET); something like this:
$.get(page)
.done(function(xml) {
// Worked, do something with the XML
})
.fail(function() {
// Failed, show/handle the error
});
try this
$user = $_REQUEST["usertype"];