Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
django:通过JQuery传递特定表单数据_Django_Jquery - Fatal编程技术网

django:通过JQuery传递特定表单数据

django:通过JQuery传递特定表单数据,django,jquery,Django,Jquery,如何通过Django中的Jquery传递任何特定的表单值进行处理?我想通过JQuery将表单中标签“machine”的值传递给views.py。这是我的密码: template.py: <head> <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script> <script type="text/javascript"> $(docum

如何通过Django中的Jquery传递任何特定的表单值进行处理?我想通过JQuery将表单中标签“machine”的值传递给views.py。这是我的密码:

template.py:

<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">

$(document).ready(
                 function() {  

                    $("#submit").click(function (event) {
                        event.preventDefault();
                        var machine = $("#machine").val();    //taking the machine value
                        var data = { machineID: machine};     //data dictionary
                        var url = "/vsawebauto/automation/results/job_processing";
                        $.getJSON(url, data, function(machines) {
                                $("#progress").text(machines[0].fields['machine_name']);
                        });                            
                      });                           
});
</script>
</head>

<body>
<form name="resultsForm" method="post">
{% csrf_token %}

<br><label id="machine" value="{{ selected_machine }}">Selected Machine: {{ selected_machine }}</label></br>
<br><input type="submit" id="submit" value="Submit Job" /></br>
<br><div class="progress" id="progress"></div></br>
</form>
</body>
</html>

调试代码时,views.py中的machineID具有布尔值'False'(其值应为$(“#machine”).val()从templates.py传递,即'1')

首先使用$.getJSON,然后在request.POST中查找machineID

您应该使用
request.GET.GET('machineID',False)

其次,我会想象你的表单将通过POST提交,在提交按钮上附加一个点击事件是没有意义的

<script type="text/javascript">
$(document).ready(function() {
$("#myform").submit(function(event){
    event.preventDefault(); 
    var machine = $("#machine").val();
    var data = { machineID: machine};
    var url = "/vsawebauto/automation/results/job_processing";
    $.getJSON(url, data, function(machines) {
       $("#progress").text(machines[0].fields['machine_name']);
    });  
});
</script>

<form id="myform">
  <br><label id="machine" value="{{ selected_machine }}">Selected Machine: {{ selected_machine }}</label></br>
  <br><input type="submit" name="submit" value="Submit"> < /br>
  <br><div class="progress" id="progress"></div></br>
</form>

$(文档).ready(函数(){
$(“#myform”).submit(函数(事件){
event.preventDefault();
var machine=$(“#machine”).val();
var data={machineID:machine};
var url=“/vsawebauto/automation/results/job_processing”;
$.getJSON(url、数据、函数(机器){
$(“#进度”).text(机器[0]。字段['machine#u name']);
});  
});

所选机器:{{所选机器}




<script type="text/javascript">
$(document).ready(function() {
$("#myform").submit(function(event){
    event.preventDefault(); 
    var machine = $("#machine").val();
    var data = { machineID: machine};
    var url = "/vsawebauto/automation/results/job_processing";
    $.getJSON(url, data, function(machines) {
       $("#progress").text(machines[0].fields['machine_name']);
    });  
});
</script>

<form id="myform">
  <br><label id="machine" value="{{ selected_machine }}">Selected Machine: {{ selected_machine }}</label></br>
  <br><input type="submit" name="submit" value="Submit"> < /br>
  <br><div class="progress" id="progress"></div></br>
</form>