User Tag List

Ցույց են տրվում 1 համարից մինչև 3 համարի արդյունքները՝ ընդհանուր 3 հատից

Թեմա: PHP AJAX

  1. #1
    Սկսնակ անդամ
    Գրանցման ամսաթիվ
    26.07.2011
    Գրառումներ
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP AJAX

    Բարև ձեզ, ժողովուրդ կօգնեք ,ոչ մի կերպ չեմ հասկանում որտեղա սխալը,

    Չատ եմ գրում,նորմալ աշխատումա մի քանի էջում ,իսկ մնացածում չի աշխատում,ավելի կոնկրետ, ՕԿ սեղմելուց հետո պետքա բազայում գրանցի նոր տող,
    Ajax ին էտքանել լավ չեմ տիրապետում, բայց իմ գրած օրինակում հասկանում եմ որը ինչ դերա տանում .

    Էս էլ կոդը:

    <?php
    $agent = $_SERVER['HTTP_USER_AGENT'];


    if(stristr($agent, 'UBrowser')) $agent = 'UBrowser'; //Opera?
    elseif(stristr($agent, 'MSIE')) $agent = 'IE'; //Internet exploler?
    elseif(stristr($agent, 'Firefox')) $agent = 'Firefox'; //Mozilla?
    // elseif(stristr($agent, 'Chrome')) $agent = 'Chrome'; //Mozilla?


    ?>

    <style type="text/css">




    #aside1 {

    position: fixed;
    z-index: 101;
    right:20%;
    bottom:0;
    width:150px;
    height:30px;
    backgroundack;
    opacity:0.85;
    color:#fff;
    cursor:pointer;
    padding-toppx;
    text-align: center;
    displayock;
    }

    #mychatbox{
    position: fixed;
    z-index: 101;
    right:16%;
    bottom:0;
    height:410px;
    width:270px;
    backgroundack;
    opacity:0.87;
    border-top-right-radius: 10px;
    border-top-left-radius: 10px;
    display:none;
    }

    #mychattop{
    width:270px;
    position: absolute;
    top:0;
    border-top-right-radius: 10px;
    border-top-left-radius: 10px;
    backgroundack;
    font-size:25px;
    color:#fff;
    text-align: right;
    font-weight:bold;
    padding-right: 7%;
    padding-top:3%;
    padding-bottom: 2%;
    displayock;
    cursor:pointer;
    border-bottom:1px solid #353434;

    }

    #chattext{

    position: absolute;
    bottom:15%;
    background:#191616;
    width:266px;
    height:78%;
    margin:2px;
    overflow-y: scroll;
    overflow-x: hidden;
    }


    .onemessage{
    <?php if($agent=='Firefox')
    echo 'font-weight:bolder;';
    ?>
    font-size:13px;
    backgroundack;
    color:white;
    opacity: 1;
    display: table;
    width:250px;
    margin:1px;
    text-align: left;
    margin-bottom: 2px;
    padding:5px;
    }

    #avelacnel{
    font-weight:bolder;
    position: absolute;
    bottom:0;
    /*background:red;
    */height:18%;
    width:266px;
    margin:2px;
    padding-left: 10px;
    }

    #chatmes{
    float:left;
    resize: none;
    background:#fbfbfb;
    opacity:0.92;
    colorack;

    margin-top:20px;
    border:none;
    border-top-left-radius: 5px;
    border-bottom-left-radius: 5px;
    }
    #chatbut{
    margin-top:20px;


    <?php if($agent=='Firefox')
    echo 'height:47px;';
    else
    echo 'height:49px;' ?>
    color:white;
    background: #dc0909;

    border:none;
    border-top-right-radius: 5px;
    border-bottom-right-radius: 5px;
    }

    </style>


    <script type="text/javascript">

    function cuctal(){
    var cht=document.getElementById("aside1");
    cht.style.display='none';
    var chtbox=document.getElementById("mychatbox");
    chtbox.style.display='block';
    }


    function taqcnel(){
    var cht=document.getElementById("aside1");
    cht.style.display='block';
    var chtbox=document.getElementById("mychatbox");
    chtbox.style.display='none';
    }

    function getdetails(){
    var chatmessage = $('#chatmes').val();
    var usrname = $('#usernamme').val();
    var usrid = $('#userid').val();
    $.ajax({
    type: "POST",
    url: "chat/send",
    data: {chatmes:chatmessage, usname:usrname , usid:usrid},
    async: true
    });
    $('#chatmes').val('');
    }

    // setInterval(function(){
    // $("#chattext").load("chat/view#chattext");
    // }, 6000);



    </script>

    <!-- START CHAT -->
    <div onclick="cuctal()" id="aside1">Չատ
    </div>
    <div id="mychatbox">
    <div onclick="taqcnel()" id="mychattop">-</div>
    <div id="chattext">

    <?php require_once (ROOT.'/view/chat/chat.php');
    ?>

    </div>



    <div id="avelacnel">



    <?php if(isset($_SESSION['user'])) : ?>

    <textarea <?php if($agent=='Firefox') echo 'rows="2" cols="20"';elseif($agent=='UBrowser') echo 'rows="3" cols="24"'; else echo ' rows="3" cols="26"'; ?> type="text" id="chatmes" name="message" /></textarea>
    <input type="hidden" name="" id="usernamme" value="<?php echo $user['username']; ?>" />
    <input type="hidden" name="" id="userid" value="<?php echo $user['id']; ?>" />

    <input type="submit" id="chatbut" onclick="getdetails()" value="OK">
    <?php else : ?><br>
    <a style="font-size:12px;color:white;" href="/login">Մուտք գործեք կամ գրանցվեք չատից օգտվելու համար </a>
    <?php endif ?>

    </div>
    </div>
    <!-- END CHAT -->
    Էս տեղադրվածա ֆուտերում,

    public function actionSend()

    {




    $result=false;




    $chatmes=htmlentities($_POST['chatmes']);


    $usid=$_POST['usid'];
    $ch_date=date_default_timezone_set('Asia/Yerevan');
    $ch_date=date("m.d.y"." / "."H:i");
    $usname=$_POST['usname'];

    if(strlen($chatmes)>=2)
    {
    $db = Db::getConnection();
    if(!$db) {echo "vuavduvuda";die;}

    $sql = 'INSERT INTO chat (chatmes,usid,ch_date,usname) VALUES ("'.$chatmes.'","'.$usid.'","'.$ch_date.'","'.$usname.'")';
    $result = $db->prepare($sql);
    $result->execute();



    }



    return true;

    }
    Էսել սերվերի մասնա

  2. #2
    Սկսնակ անդամ ԿանաչԸնծա-ի ավատար
    Գրանցման ամսաթիվ
    22.04.2015
    Գրառումներ
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ողջույն։

    Խառը բան եք արել, գոնե առանձնացրեք CSS, JS ու HTML, որ ավելի հեշտ լինի նայել հասկանալ ինչ ա կատարվում։

  3. Գրառմանը 1 հոգի շնորհակալություն է հայտնել.

    Աթեիստ (04.08.2016)

  4. #3
    Սկսնակ անդամ
    Գրանցման ամսաթիվ
    26.07.2011
    Գրառումներ
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    լավ


    CSS
    <?php
    $agent = $_SERVER['HTTP_USER_AGENT'];


    if(stristr($agent, 'UBrowser')) $agent = 'UBrowser'; //Opera?
    elseif(stristr($agent, 'MSIE')) $agent = 'IE'; //Internet exploler?
    elseif(stristr($agent, 'Firefox')) $agent = 'Firefox'; //Mozilla?
    // elseif(stristr($agent, 'Chrome')) $agent = 'Chrome'; //Mozilla?


    ?>

    <style type="text/css">




    #aside1 {

    position: fixed;
    z-index: 101;
    right:20%;
    bottom:0;
    width:150px;
    height:30px;
    backgroundack;
    opacity:0.85;
    color:#fff;
    cursor:pointer;
    padding-toppx;
    text-align: center;
    displayock;
    }

    #mychatbox{
    position: fixed;
    z-index: 101;
    right:16%;
    bottom:0;
    height:410px;
    width:270px;
    backgroundack;
    opacity:0.87;
    border-top-right-radius: 10px;
    border-top-left-radius: 10px;
    display:none;
    }

    #mychattop{
    width:270px;
    position: absolute;
    top:0;
    border-top-right-radius: 10px;
    border-top-left-radius: 10px;
    backgroundack;
    font-size:25px;
    color:#fff;
    text-align: right;
    font-weight:bold;
    padding-right: 7%;
    padding-top:3%;
    padding-bottom: 2%;
    displayock;
    cursor:pointer;
    border-bottom:1px solid #353434;

    }

    #chattext{

    position: absolute;
    bottom:15%;
    background:#191616;
    width:266px;
    height:78%;
    margin:2px;
    overflow-y: scroll;
    overflow-x: hidden;
    }


    .onemessage{
    <?php if($agent=='Firefox')
    echo 'font-weight:bolder;';
    ?>
    font-size:13px;
    backgroundack;
    color:white;
    opacity: 1;
    display: table;
    width:250px;
    margin:1px;
    text-align: left;
    margin-bottom: 2px;
    padding:5px;
    }

    #avelacnel{
    font-weight:bolder;
    position: absolute;
    bottom:0;
    /*background:red;
    */height:18%;
    width:266px;
    margin:2px;
    padding-left: 10px;
    }

    #chatmes{
    float:left;
    resize: none;
    background:#fbfbfb;
    opacity:0.92;
    colorack;

    margin-top:20px;
    border:none;
    border-top-left-radius: 5px;
    border-bottom-left-radius: 5px;
    }
    #chatbut{
    margin-top:20px;


    <?php if($agent=='Firefox')
    echo 'height:47px;';
    else
    echo 'height:49px;' ?>
    color:white;
    background: #dc0909;

    border:none;
    border-top-right-radius: 5px;
    border-bottom-right-radius: 5px;
    }

    </style>

    Javascript
    <script type="text/javascript">

    function cuctal(){
    var cht=document.getElementById("aside1");
    cht.style.display='none';
    var chtbox=document.getElementById("mychatbox");
    chtbox.style.display='block';
    }


    function taqcnel(){
    var cht=document.getElementById("aside1");
    cht.style.display='block';
    var chtbox=document.getElementById("mychatbox");
    chtbox.style.display='none';
    }

    function getdetails(){
    var chatmessage = $('#chatmes').val();
    var usrname = $('#usernamme').val();
    var usrid = $('#userid').val();
    $.ajax({
    type: "POST",
    url: "chat/send",
    data: {chatmes:chatmessage, usname:usrname , usid:usrid},
    async: true
    });
    $('#chatmes').val('');
    }

    // setInterval(function(){
    // $("#chattext").load("chat/view#chattext");
    // }, 6000);



    </script>

    HTML
    <!-- START CHAT -->
    <div onclick="cuctal()" id="aside1">Չատ
    </div>
    <div id="mychatbox">
    <div onclick="taqcnel()" id="mychattop">-</div>
    <div id="chattext">

    <?php require_once (ROOT.'/view/chat/chat.php');
    ?>

    </div>



    <div id="avelacnel">



    <?php if(isset($_SESSION['user'])) : ?>

    <textarea <?php if($agent=='Firefox') echo 'rows="2" cols="20"';elseif($agent=='UBrowser') echo 'rows="3" cols="24"'; else echo ' rows="3" cols="26"'; ?> type="text" id="chatmes" name="message" /></textarea>
    <input type="hidden" name="" id="usernamme" value="<?php echo $user['username']; ?>" />
    <input type="hidden" name="" id="userid" value="<?php echo $user['id']; ?>" />

    <input type="submit" id="chatbut" onclick="getdetails()" value="OK">
    <?php else : ?><br>
    <a style="font-size:12px;color:white;" href="/login">Մուտք գործեք կամ գրանցվեք չատից օգտվելու համար </a>
    <?php endif ?>

    </div>
    </div>
    <!-- END CHAT -->
    Վերջին խմբագրող՝ Dawson: 04.08.2016, 10:03:

Թեմայի մասին

Այս թեման նայող անդամներ

Այս պահին թեմայում են 1 հոգի. (0 անդամ և 1 հյուր)

Համանման թեմաներ

  1. AJAX + PHP + cookies
    Հեղինակ՝ Shahen., բաժին` Վեբ ծրագրավորում
    Գրառումներ: 5
    Վերջինը: 30.01.2012, 20:26
  2. Email ձև AJAX-ով և PHP-ով
    Հեղինակ՝ T!gran, բաժին` Վեբ
    Գրառումներ: 0
    Վերջինը: 05.03.2009, 19:40

Էջանիշներ

Էջանիշներ

Ձեր իրավունքները բաժնում

  • Դուք չեք կարող նոր թեմաներ ստեղծել
  • Դուք չեք կարող պատասխանել
  • Դուք չեք կարող կցորդներ տեղադրել
  • Դուք չեք կարող խմբագրել ձեր գրառումները
  •