当前位置: 动力学知识库 > 问答 > 编程问答 >

Receive Jquery/Ajax Post Request in PHP

问题描述:

I have Jquery/Ajax Code which sends Text Fields Data to PHP Script. But i don't know how i can receive that data and process for Validation.

Here is the Ajax Code:

$("#button").click(function (e) {

var dataa = $("#survay").serialize();

var data = $("#yourName ,#emailAdress , #phoneNumber , #zipCode").serialize();

$.ajax({

type: "POST",

url: 'processRequest.php',

data: dataa,

beforeSend : function(){

$('.eDis').empty().append('<div class="loader"><img src="images/32.gif" /> Loading...</div>').show();

},

success: function (html) {

if(html !='1') {

$('.eDis').empty().append(html).addClass("actEr");

setTimeout(function(){

$('.eDis').removeClass("actEr")}, 5000);

}

if(html == '1') {

$('.eDis').empty().append('<div class="success">Your Message has been sent</div>').addClass("actEr");

window.location ='../thank-you.html';

}

if(html =='0') { $('.eDis').empty().append('Error..').addClass("actEr"); setTimeout(function(){

$('.eDis').removeClass("actEr")}, 3000);

}}

});

});

processRequest.php should be PHP script which will handle all the texts fields data.

If above Text fields data is valid then i want it to Proceed further and redirect the page to thank-you.html

.eDis is CSS class, which i want to use to display valid,Invalid fields information.

It is in HTML.

网友答案:

Based on your information, I can't give you exact code, but, this is what you can do:

<?php
if(isset($_POST['itemName']) && isset($_POST['anotherItemName']) /* ...and so on */){
    if($_POST['itemName'] == $validSomething)
        echo 'WOW!';
}
else
    echo 'error';
?>

What you are "echoing" is what you get in "success" data in your javascript.

分享给朋友:
您可能感兴趣的文章:
随机阅读: