duanhui5344 2014-01-24 13:16
浏览 67
已采纳

序列化的AJAX $ _POST不为空,但单个$ _REQUEST为空

I'm making an AJAX Call like this:

$( "#submit_jobs_preview" ).click(function(e) {
    var postData = $('#new_job_form').serialize();
    var formURL = "ajax.xxx.php";

    $.ajax({
    type: 'POST',
    url: formURL,
    data: {submit_jobs_preview: postData },
    success: function(data){
        alert(data);
        }   
    });     
    e.preventDefault(); //STOP default actio
});

In php i echo:

echo $_POST['submit_jobs_preview'];

This $_POST shows all values i put in my form correctly like this:

new_job_city=Berlin&new_job_name=Manager etc.

But if i want a single $_REQUEST from this $_POST like this:

 if($_POST['submit_jobs_preview']){
    echo $city = mysql_real_escape_string($_REQUEST['new_job_city']);
 }

the alert is empty.

Why is that? :)

Thanks in advanced!

UPDATE

Full return of data:

XHR Loaded (autocomplete.php - 200 OK - 105.99994659423828ms - 354B) VM2106:3
new_job_city=Halle&new_job_job=Flugbegleiter&new_job_other_job=&job_zielgruppe=Auszubildende&new_job_phone=4921663965439&new_job_email=kleefeld%40dsc-medien.de&new_job_detailhead=F%C3%BCr+unser+zentrales+Marketing+mit+Sitz+in+der+Hauptverwaltung+in+der+City+von+D%C3%BCsseldorf+suchen+wir+zum+n%C3%A4chstm%C3%B6glichen+Termin+eine%2Fn&new_job_time=Vollzeit&teilzeit_std=&new_job_tasks=&new_job_profile=&new_job_advantage=&new_job_creatorId=1&new_job_creationDate=1390569795&new_job_scope=Airport+Service&new_job_niederlassung=7&new_job_active=0 
  • 写回答

2条回答 默认 最新

  • dozc58418381 2014-01-24 13:49
    关注

    You don't need to use {submit_jobs_preview: postData } if it is not necessary. I will give you another hint. Use following ajax;

    $( "#submit_jobs_preview" ).click(function(e) {
        var postData = $('#new_job_form').serialize();
        var formURL = "ajax.xxx.php";
    
        $.ajax({
        type: 'POST',
        url: formURL,
        data: postData,
        success: function(data){
            alert(data);
            }   
        });     
        e.preventDefault(); //STOP default actio
    });
    

    and on php side;

    if($_POST['new_job_city']){
        echo $city = mysql_real_escape_string($_REQUEST['new_job_city']);
    }
    

    In this case you can use field names directly.

    Another hint:

    You can put a hidden value on your form like,

    <input type="hidden" name="submit_jobs_preview" value="true"/>
    

    and js side will be same as above in my answer, and in php side you can check like;

    if($_POST['submit_jobs_preview']){
        echo $city = mysql_real_escape_string($_REQUEST['new_job_city']);
    }
    

    As you can see, you can send your post value as hidden field and make your check

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器