0

i do have 3 input text which are of "type:number" and a save button. i want to insert the these 3 input text data into the database using ajax. i have written the code as follows:

<fieldset><legend>Response Times</legend></fieldset> 
    <form class="form">
        <div class="control-group">
            <label class="control-label">High Priority</label>
            <div class="controls">
            <input type="number" name="high" id="sval"/>Days
            </div>
        </div>
        <div class="control-group">
            <label class="control-label ">Low Priority</label>
            <div class="controls">
            <input type="number" name="high" id="sval"/>Days</div>
        </div>
         <div class="control-group">
            <label class="control-label ">Normal</label>
            <div class="controls">
            <input type="number" name="high" id="sval"/>Days </div>
        </div>
        <button id="insert" class="btn btn-primary">Save</button>
</form>
<script type="text/javascript" src="<?php echo $BASE;?>scripts/data/projects_service.js"></script>

and my query is

Insert into app_settings(kunnr,skey,sval) Values ('0001000383','hp_days','1') 
Insert into app_settings(kunnr,skey,sval) Values ('0001000383','lp_days','3')
Insert into app_settings(kunnr,skey,sval) Values ('0001000383','np_days','2')

which are hard coded but i dont want hard coded data.my problem is that only sval values are showing in the view but what about this skey value.and i want o insert it using ajax and i have tried this by ajax that i have written as follows:

$(function () {
    $("#insert").click(function () {
        var id = $("#id").val();
        var sval = $("#sval").val();
        $.post(root + "data/projects_service?json", { pid: id, sval: sval }, function (data) { });

    });        
});

please suggest me on this..

4

3 回答 3

2

html代码

<html>
<body>

<fieldset><legend>Response Times</legend></fieldset> 
    <form class="form">
        <div class="control-group">
            <label class="control-label">High Priority</label>
            <div class="controls">
            <input type="number" name="high" id="kunnr"/>Days
            </div>
        </div>
        <div class="control-group">
            <label class="control-label ">Low Priority</label>
            <div class="controls">
            <input type="number" name="high" id="skey"/>Days</div>
        </div>
         <div class="control-group">
            <label class="control-label ">Normal</label>
            <div class="controls">
            <input type="number" name="high" id="sval"/>Days </div>
        </div>
        <button id="insert" class="btn btn-primary">Save</button>
</form>

</body>
</html>

jQuery代码

$(function()
{   
    $("#insert").click(function() 
    {
        var kunnr = $("#kunnr").val;
        var sKey = $("#skey").val;
        var sVal = $("#sval").val;
        var dataString = "kunnr="+kunnr+"&sKey="+sKey+"&sVal="sVal;
        $.ajax(
        {
            type: "GET",
                url: "your url", // in the page of url write the code to insert in db
                data: dataString,
                success: function(result) 
                {               
                    alert(result); // you can just check whether the row is inserted or not.
                }
            });
    });
});
于 2012-12-01T10:39:59.790 回答
2

看看这一行:

var id = $("#id").val();

这一行意味着您从 id 名称为“id”的元素中获取值。

因此 Js 无法找到该元素的值,因为它不存在。

为什么你使用 id="sval"?id 参数应始终唯一。将它们的 id 分别更改为“hp”、“lp”、“n”,并在 jQ 中获取 3 个值。)

var hp = $("#hp").val();
var lp = $("#lp").val();
var n = $("#n").val();
于 2012-12-01T10:18:13.537 回答
0

在“您的 url”文件中,您可以访问变量hp,例如通过$_GET['hp'].

你能告诉我 kunnr 在不同的日子里应该是不同的参数吗?如果不是,那么您可以通过以下方式进行查询:

Insert into app_settings(kunnr,skey,sval) Values ('0001000383','hp_days',$_GET['hp']) 
Insert into app_settings(kunnr,skey,sval) Values ('0001000383','lp_days', $_GET['lp'])
Insert into app_settings(kunnr,skey,sval) Values ('0001000383','np_days',$_GET['n'])
于 2012-12-05T22:05:22.837 回答