Reputation: 1174
I need to redirect user to another page called "free.php" from index page, if the user checked the check-box without url change using jquery. I have created an example here,
Here the check box is validating, but I couldn't redirect to free.php.Though I am new to jquery and ajax, I couldn't find the answer. what I need to change in my code?
Thanks!
Upvotes: 1
Views: 374
Reputation: 35409
Not possible to redirect using an $.ajax
call unless you physically redirect in one of the handlers. But, that would defeat your intent of not changing the browser url.
The only ways to not change the browser's URL is to:
iframe
and and change it's source to free.php
Handle ajax
and inject HTML
response from free.php
into the DOM
:
$.ajax({
type: "POST",
url: "free.php",
data: formdata,
dataType : 'html',
success : function(html) { $('div.result').html(html); }
});
Upvotes: 1
Reputation: 1000
I do not think $.ajax
is what you are looking to do from your description, $.ajax() is used to make a call to a page and get a response from it without reloading.
I would remove the ajax call all together, and change your form title to <form method="POST" action="free.php" id="agreeForm" name="Agree">
$(document).ready(function() {
$("#agreeForm").submit(function()
{
if (!$("#agree").is(':checked'))
{
document.getElementById("err").innerHTML="you must agree to terms if you would like to access web";
return false;
}
});
});
Upvotes: 0
Reputation: 1008
Why not set the action to free.php and remove the ajax call? so it would be:
$("#agreeForm").submit(function()
{
if (!$("#agree").is(':checked'))
{
document.getElementById("err").innerHTML="you must agree to terms if you would like to access web";
return false;
}
});
Upvotes: 0