第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

ajax post 返回的數(shù)據(jù)是null

ajax post 返回的數(shù)據(jù)是null

慕哥9229398 2019-03-13 14:15:58
因?yàn)閒orm提交的時(shí)候頁(yè)面會(huì)自動(dòng)提交到/apply 這個(gè)處理頁(yè)面,返回JSON數(shù)據(jù)所以用ajax重定向到/applysuccess重定向成功了可是數(shù)據(jù)怎么沒(méi)提交成功的樣子 獲取的時(shí)候看到都是null求幫助//ajax的代碼 $.ajax({        type: 'post',        url: '/apply',        async: true,        dataType: 'json',        data: $('#sub').serialize(),        success: function (data) {            $("#sub").attr("method", 'GET').attr("action", '/applysuccess');            $('#apply').html('<h3>' + data.message + '</h3>');            $('.count').html(' ' + data.count + ' ');        }    });<!--這是表單的代碼--><form action="/apply" method="post" id="sub">                <div class="form-group fl col-md-4">                    <input class="form-control" name="first_name" placeholder="first name" required>                    <input class="form-control" name="last_name" placeholder="last name" required>                </div>                <div class="form-group fl col-md-4">                    <input class="form-control" name="position_id" placeholder="position id" required>                    <input class="form-control" name="years_experience" placeholder="years experience" required>                </div>                <div class="form-group fl col-md-4">                    <input class="form-control" name="expertise" placeholder="expertise" required>                    <button id="applyBtn" type="submit" class="btn btn-primary btn-lg">Apply for Job NOW</button>                </div>            </form>請(qǐng)輸入代碼
查看完整描述

1 回答

?
慕田峪7331174

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超13個(gè)贊

更新:


<form id="form" ...>

    ...

    <input type="submit" value="提交"/>

</form>

<script>

    document.querySelector('#form').onsubmit = e => {

        // 你有修改 action 的做法,所以這里可能需要判斷一下現(xiàn)在 acion 的值然后做不同的操作

        const action = $('#suib').attr('action')

        if (action === '/apply') {

            $.ajax({

                type: 'post',

                url: '/apply',

                async: true,

                dataType: 'json',

                data: $('#sub').serialize(),

                success: function (data) {

                    $("#sub").attr("method", 'GET').attr("action", '/applysuccess');

                    $('#apply').html('<h3>' + data.message + '</h3>');

                    $('.count').html(' ' + data.count + ' ');

                }

            })

        } else if (action === '/applysuccess') {

            // TODO ...

        }


        // 阻止表單的默認(rèn)行為

        return false;

    }

</script>

你 ajax 里都沒(méi)傳要 post 的數(shù)據(jù)啊。


查看完整回答
反對(duì) 回復(fù) 2019-04-04
  • 1 回答
  • 0 關(guān)注
  • 933 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)