jQuery Ajax发布,将它们添加到数据库,返回数据并再次重复该过程 [英] jQuery Ajax Post, Add them to DB, Return Data and repeat the Process again

查看:108
本文介绍了jQuery Ajax发布,将它们添加到数据库,返回数据并再次重复该过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全感到困惑,所以请让我们更清楚地解释逻辑.

I'm completely confused so please let explained the logic clearer.

在这里我从数据库获取数据.

Here where i get my data from db.

index.php


    $sorular_hepsi = mysql_query("select * from tblsorular where hafta=1 order by rand() limit 2");
    $soru_ust = mysql_fetch_assoc($sorular_hepsi);
    $soru_id = $soru_ust_rs["id"];
    $soru_grup_id = $soru_ust["sId"];

    $soru1 = $soru_ust["soru"];

    $sorular = mysql_query("select * from tblsorular where sId=$soru_grup_id");
    $totalKayit = mysql_num_rows($sorular_rs);

    while ( $sorular_rs=mysql_fetch_assoc($sorular)) {
        $sorular2[] = $sorular_rs["soru"];
        $sorular2Id[] = $sorular_rs["id"];
    }

$userId = 1234;

这是index.php

    <div id="sorugonder" class="soruStyle">
        <a href="#" class="sorugonder" id="<?=$sorular2Id[0]?>"><?=$sorular2[0]?></a>
    </div>

    <div id="soru_sag" class="soruStyle">
        <a href="#" class="sorugonder2" id="<?=$sorular2Id[1]?>"><?=$sorular2[1]?></a>
    </div>

这是我的ajax函数,用于将我的数据发送到islem.php

And here is my ajax function to send my data to islem.php

$(function() {
    $(".sorugonder").click(function() {
    // $('#load').fadeIn();
    var commentContainer = $(this).parent();

    var id = $(this).attr("id");
    var string = 'id='+ id ;

    $.ajax({
       type: "POST",
       url: "islem.php?islem=soruKayit",
       data: string,
       cache: false,

       success: function(data){

       commentContainer.slideUp('slow', function() {$(this).remove();});
             $('#sorugonder').fadeOut(1000);
             $('#soru_sag').fadeOut(2000);

             console.log(string);
             // alert(id);
            }
        });

        return false;

    });
});

此功能打印控制台日志为id=xx

This function printing console log as id=xx

这是我的islem.php页面,用于获取Ajax数据

And here is my islem.php page to get ajax data

if(isset($_POST["islem"]) && $_POST["islem"]=="soruKayit"){

    header('Content-type: application/json');

    $id= $_POST['string'];
    $cevapTarihi = date("d-m-Y H:i:s");

    $cevapId = json_encode($id);
    $userId = 1234;

     $kayit = @mysql_query("INSERT INTO tblk_skor VALUES(NULL, $userId,$cevapId,$cevapTarihi)");

        if(!$kayit){
                echo "Error:".mysql_error();
        }

        die();

   }

我有4张不同的png图片,我正在将它们用作它们的背景.例如:

I've 4 different png pictures and i'm using them as a background for them. For example :

$1 = '<img src="../img/1.png" />';
$2 = '<img src="../img/2.png" />';
$3 = '<img src="../img/3.png" />';
$4 = '<img src="../img/4.png" />';

我在每个后期处理中都更改了我列出的数据背景.但是我无法弄清楚我该如何放置它们以及在何处放置它们?

I have change my listed datas background on each post process. But i couldn't figure it out how and where i have to put them?

$.ajax函数无法将我的数据发送到islem.php或无法获取.

$.ajax function doesn't send my data to islem.php or i can't get it.

简单地:

  1. 我想将记录添加到数据库(只是id)
  2. 我必须执行回调函数,以10次不同的记录重复此过程10次.
  3. 完成10次记录后,我将计算结果并重定向到另一页.
  4. 每个帖子步骤都要更改背景.
  5. 倒计时!我必须将倒数计时放入div中,以便用户在10秒内单击它.否则,我必须执行另一个错误功能才能再次启动所有这些功能.我找不到合适的倒计时脚本来演示我的功能.

就是这个.

有什么建议吗?

推荐答案

ajax中的data选项应该包含您要发送到服务器的数据.

The data option in ajax is supposed to contain the data you want to send to the server.

$.ajax({
   type: "POST",
   url: "islem.php",
   data: [{ name:'islem', value:'soruKayit' },
          { name:'id', value:id }],
   cache: false,
   ....

这篇关于jQuery Ajax发布,将它们添加到数据库,返回数据并再次重复该过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆