簡體   English   中英

jQuery-發送數據並在php端獲取數據

[英]jQuery - sending data and taking the datas in php side

這是我的HTML表格

{foreach value=artist2 from=$artist}

                  <form name=form1 method=post action=action_page.php onsubmit='return validate(this)'>

                <br />

                <span class="checkArtist" id="hide_{$artist2.MOVIE_ID}-{$artist2.PERSON_ID}-374"><input type="checkbox" name="artist[]" value="{$artist2.MOVIE_ID}-{$artist2.PERSON_ID}-374"  />{$artist2.NAME_SURNAME}<br /></span>


                {/foreach}
                <p align="right">
                <a style="float: right" ><br />
                    <input type="button" name="checkArtistButton" value="Seçilenleri Sil" onclick="deleteData('artist[]');" id="ajaxCheckbox" /></a></p>
                <br >
                  </form>

在jQuery方面

我接受文字值和ID

   function AddData(par){

        var artistName =  $("input[name='"+par+"']").attr('id') + '-'+$("input[name='"+par+"']").val();

        alert(artistName);

       $.post('/management/AddDataAjax2', 
        {
           data: JSON.stringify({"artistName": "artistName"})
        },
        function(response){
            alert("Başarıyla silindi");
        });
    }

如您在上面的代碼中看到的,當我提醒時,我看到了所有需要的數據

在此處輸入圖片說明

我認為數據不會發送到我的php端

這是我的PHP方面,但一無所獲

  public function AddDataAjax2() {

        $json = $_POST['json'];
        $data = json_decode($json, true);
        $arr = explode("-",$data);


        $personID = NCore::db('PERSON')->select('ID')->eq('NAME_SURNAME', $arr[2])->fetch(FETCH_MODEL_BASE, true);
            if($personID)
                NCore::db('PERSON_MOVIE')->insertAsArray(array('PERSON_ID' =>$personID->id,'MOVIE_ID'=> $arr[0],'JOB_ID' => $arr[1]));

     }

在您的PHP代碼中,您需要運行代碼。 您已經聲明了函數,但尚未調用它。 您的PHP代碼應如下所示:

<?php
    AddData2Ajax2();

     public function AddDataAjax2() {

            $json = $_POST['json'];
            $data = json_decode($json, true);
            $arr = explode("-",$data);


            $personID = NCore::db('PERSON')->select('ID')->eq('NAME_SURNAME', $arr[2])->fetch(FETCH_MODEL_BASE, true);
                if($personID)
                    NCore::db('PERSON_MOVIE')->insertAsArray(array('PERSON_ID' =>$personID->id,'MOVIE_ID'=> $arr[0],'JOB_ID' => $arr[1]));

         }
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM