dongli8862 2010-12-07 21:27
浏览 131
已采纳

jQuery / Ajax PHP POST调用

I am posting a form with the following:

if ( flag ) {
jQuery.ajax({
    url: 'submit_licence.php',
    dataType: 'json',
    type: 'POST',
    data: 'flag=' + flag + '&region=' + jQuery('#licenceRegion').val() + '&lnum=' + jQuery('#enterLicence').val() + '&fname=' + jQuery('#fname').val() + '&lname=' + jQuery('#lname').val(),
    success: function( data ) {

    }
});
}

The HTML

<input class="buttondb4 white2 large" type="text" value=" " id="enterLicence" />
<input type="hidden" name="licenceRegion" id="licenceRegion" value="" /> 
<input type="hidden" name="fname" id="fname" value="First" /> 
<input type="hidden" name="lname" id="lname" value="Last" />

and my PHP:

if ($_POST){
$lnum     = noescape($_POST['lnum']);
$fname    = noescape($_POST['fname']);
$lname    = noescape($_POST['lname']);
$region   = noescape($_POST['region']);
$flag     = noescape($_POST['flag']);  

//mysql query here

}

But when its posted, it is not retrieving any of the posted data (the posted values are blank)

Why is it not pulling the data? What am I missing? What have I done wrong?

Unfortunately I cannot post the entire script/page due to it being a private project for a client although I think I have provided enough information for what I am trying to do.

  • 写回答

7条回答 默认 最新

  • douhe6255 2010-12-07 21:39
    关注

    Read this on SO

    You need to wait for the return of the function:

    onSubmit="return sendData()"
    

    Otherwise the form will be submitted immediatly and does'nt wait till data is changed.

    inside the function replace this

    document.data.submit();
    

    with this:

    return true;
    

    Link posted in comment above

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

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作