dregvw1801 2017-08-01 07:27
浏览 45

使用ajax提交帖子数据只能调用一次

I have problem with this code:

function sendData(nr) {
    var data = $("#myform"+ nr).serialize();

    // debug regeltje
    console.log(data);

    jQuery.ajax({
        url: "inc/update.php",
        data: data,
        type: "POST",
        cache: false,
        success:function(data)
        {
            if(data=='success') {
                $("#container").load(window.location + " #container");
            //  alert(data);
            } else {
                $("#container").load(window.location + " #container");
            }
        }
    });
}

the first time I call this function it is working fine. But the second time it isn't. Debug Console gives no result.

This is my update.php file

<?php
session_start();
include("config.php");
include("function.php");
include("class.User.php");
$Func = new Func($db);
if(isset($_SESSION['userData'])) {
    $User = new GUser($db,$Func, $_SESSION['userData']['oauth_uid']);
}

//echo var_dump($_POST);
if(isset($_POST['color'])) {
    $query = $db->query('UPDATE user_fleet SET train_row_color = "'.$db->real_escape_string($_POST['color']).'" WHERE id = "'.$db->real_escape_string($_POST['id']).'"');
}

After I refresh the whole page then it's working fine for only one time again.

Why is this happening?

I call the sendData from fleet.php

<tr style="background-color: #'.$res['train_row_color'].';">
            <form method="post" action="" id="myform'.++$i.'">
            <td>
                <select class="test" name="color" onchange="sendData('.$i.');">
                    <option value="0"></option>
                    <option value="ff0000" style="background-color: #ff0000"></option>
                    <option value="3000ff" style="background-color: #3000ff"></option>
                    <option value="36ff00" style="background-color: #36ff00"></option>
                    <option value="e400ff" style="background-color: #e400ff"></option>
                    <option value="fff000" style="background-color: #fff000"></option>
                </select>
            </td>

This is inside a while loop.

True Google Inspect and Network i see this

enter image description here

enter image description here

As you can see the second screen is not showing the form.

  • 写回答

1条回答 默认 最新

  • dongtang1910 2017-08-01 07:45
    关注

    Remove call function from HTML tag

                <select id="yourID" class="test" name="color">
    

    Do function call with javascript

    $("#yourID").on('change',function(){
    sendData($(this).val();
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答