jQuery的POST值的PHP脚本脚本、jQuery、POST、PHP

2023-09-10 20:02:44 作者:离人毁心

我要发布一些值从一个简单的HTML表单,与Ajax调用对其进行验证,如果成功提交到一个PHP脚本,并重定向到该脚本。我已经得到了ajax部分成立,只是不知道如何发布和重定向(因为如果你将一个标准的表格上没有Ajax提交)。

I want to post some values from a simple HTML form, validate them with an ajax call and if successful submit to a PHP script and redirect to that script. I have got the ajax part set up, just not sure how to post and redirect (as if you would on a standard form submit without ajax).

下面是我有:

HTML:

<div id=audiencesearch>

    <h1>Audience Search</h1>

<form id="audiencesearchform">

<p>Passion Point</p>
<select id="passionselect">
<option selected="selected">Please select</option>
    <option>3D</option>
    <option>Music</option>
<option>Playstation</option>
    </select>

<p>Gender Bias</p>
<select id="genderselect">
<option selected="selected">Please select</option>
    <option>Male</option>
    <option>Female</option>
    </select>

<p>Sort Group By Age Range</p>
<select id="ageselect">
<option selected="selected">Please select</option>
<option>Under 21</option>
    <option>21 - 30</option>
    <option>31 - 40</option>
<option>41 - 50</option>
    </select>

<br/>
<br/>

<input onClick="ajaxaudiencesearch()" class="submitaudiencesearch" value="Search" type="button"/>

AJAX调用:

Ajax Call:

 <script type="text/javascript">

function ajaxaudiencesearch(){

    var passionpoint = $("select#passionselect").val();  
    var genderbias = $("select#genderselect").val();  
    var agerange = $("select#ageselect").val();
    var passedstring = 'passion='+ passionpoint + '&gender=' + genderbias + '&age=' + agerange;

    $.ajax({
        type: "POST",
        url: "processaudiencesearch.php",
        data: passedstring,
        success:function(retval){       
            if (retval == 'oktoprocess'){

                audiencesearchprocess();

            } else {
                audiencesearcherror();
            }

        }
    })
}

function audiencesearcherror(){

    $('#audienceerror').html('GOTTA SELECT EM ALL');

}

function audiencesearchprocess(){

    window.location.href = "searchresults.php";

//THIS IS WHERE I WANT TO POST AND MOVE TO SEARCHRESULTS.PHP

}

</script>

PHP来处理Ajax:

PHP to handle Ajax:

    <?php

include('sonymysqlconnect.php'); 
session_start();

$nullselection = "Please select";

//get the posted values
$postedpassion = ($_POST['passion']);
$postedgender = ($_POST['gender']);
$postedage = ($_POST['age']);


if (($postedpassion != $nullselection ) && ($postedgender != $nullselection ) && ($postedage != $nullselection)){
    echo 'oktoprocess';
} else {
    echo 'error';
}

?>

preferably我可以使用jQuery实现这一目标。我敢肯定,这是非常简单的,但我不知道该怎么办呢?!

Preferably I could achieve this using jQuery. I'm sure it's extremely simple but I'm not sure how to do it?!

值得一提的是,这是所有正确设置。我已经使用PHP包括。

It's worth mentioning that this is all set up correctly. I have used PHP includes.

在此先感谢...

推荐答案

为什么不加动作和方法属性窗体,然后用.submit提交()?

Why not add action and method attributes to your form and then submit it with .submit()?

 
精彩推荐
图片推荐