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条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?