Catching Post data from Jquery Ajax From Submission
So I am sending form data using jQuery's ajax functionality. It all seems to work okay how ever i am not able to catch the data it posts.
I am trying to use $string = $_POST['name'] to catch the result on the page it sends to with no luck.
THE JQUERY-
$(function()
{
$('.error').hide();
$(".button").click(function() {
// validate and process form here
$('.error').hide();
var name = $("input#name").val();
if (name == "") {
$("label#name_error").show();
$("input#name").focus();
return false;
}
var email = $("input#email").val();
if (email == "") {
$("label#email_error").show();
$("input#email").focus();
return false;
}
var phone = $("input#phone").val();
if (phone == "") {
$("label#phone_error").show();
$("input#phone").focus();
return false;
}
var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone;
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "from_text_script.php",
data: dataString,
success: function() {
window.location.href="from_text_script.php"
}
});
return false;
});
});
THE FROM-
<form name="contact" action="">
<fieldset>
<label for="name" id="name_label">Name</label>
<input type="text" name="name" id="name" size="30" value="" class="text-input" />
<label class="error" for="name" id="name_error">This field is required</label><br/>
<label for="email" id="email_label">Return Email</label>
<input type="text" name="email" id="email" size="30" value="" class="text-input" />
<label class="error" for="email" id="email_error">This field is required.</label> <br/>
<label for="phone" id="phone_label">Return P开发者_运维百科hone</label>
<input type="text" name="phone" id="phone" size="30" value="" class="text-input" />
<label class="error" for="phone" id="phone_error">This field is required.</label> <br/>
<br />
<input type="submit" name="submit" class="button" id="submit_btn" value="Send" />
</fieldset>
</form>
/div> -->
Sorry about the typed code not being a screen shot. The site won't let me post images yet. Kind of silly really. Anyway... Cheers guys.
I'm not sure what you're trying to do, why does your success function redirect to the same page you're posting to?
try doing this on the page you post to:
var_dump($_REQUEST);
that will print out anything that got passed and maybe you can see what's going on.
精彩评论