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

报告相同问题?

悬赏问题

  • ¥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?