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

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据