簡體   English   中英

想要將帶有ajax的jquery變量傳遞給perl文件,並檢索cgi頁面中的值

[英]want to pass a variable from jquery with ajax to perl file and retrieve the value in the cgi page

以下是我的HTML代碼:

following is my template code : 

<html>
<head>

<script type = "text/javascript" src = "jquery.min.js"></script>
<script>
var counter = 0;
var txt1 = "group_save";
function addNew() {
// Get the main Div in which all the other divs will be added
var mainContainer = document.getElementById('mainContainer');
// Create a new div for holding text and button input elements
var newDiv = document.createElement('div');
// Create a new text input
var newText = document.createElement('input');
newText.type = "input";
newText.name = txt1+counter;
//newText.value = counter;
// Create a new button input
var newDelButton = document.createElement('input');
newDelButton.type = "button";
newDelButton.value = "Delete";
// Append new text input to the newDiv
newDiv.appendChild(newText);
// Append new button input to the newDiv
newDiv.appendChild(newDelButton);
// Append newDiv input to the mainContainer div
mainContainer.appendChild(newDiv);
counter++;
// Add a handler to button for deleting the newDiv from the mainContainer
newDelButton.onclick = function() {
mainContainer.removeChild(newDiv);
}
}
   function edit(element){
  var tr = jQuery(element).parent().parent();
    if(!tr.hasClass("editing")) {
            tr.addClass("editing");
            tr.find("DIV.td").each(function(){
                    if(!jQuery(this).hasClass("action")){
                            var value = jQuery(this).text();

                            jQuery(this).text("");
                            jQuery(this).append('<input type="text" value="'+value+'" />');

                    } else {
                            jQuery(this).find("BUTTON").text("save");
                    }
            });
    } else {
            tr.removeClass("editing");
            tr.find("DIV.td").each(function(){
                    if(!jQuery(this).hasClass("action")){
                            var value1 = jQuery(this).find("INPUT").val();
                            alert(value1);
                            jQuery(this).text(value1);
                            jQuery(this).find("INPUT").remove();
                    } else {
                            jQuery(this).find("BUTTON").text("edit");
                    }
            });
    }
}
</script>

</head>
<body >
<form name="group" method="post" action="process.cgi">
<div id="mainContainer">
<div><input type="button" value="Add" onClick="addNew()"></div>
 </div>
 <div><input type = "submit" value = "Save"></div>
</form>
[% IF count > 0%]

<b>Details of Groups</b><br>

<div class= "table">
<div class = "thead">
  <div class = "tr">

<div class = "td">ID</div>
<div class = "td">GROUP NAME</div>
<div class = "td">GROUP DESCRIPTION</div>
<div class = "td">IS ACTIVE</div>
<div class = "td"></div>
 </div>
</div>

<div class= "tbody">

[%- SET i = 0;
 WHILE i < id.size; -%]

 <form  class = "tr">
<div class = "td">&nbsp; [% id.$i %]<br/></div>
<div class = "td">&nbsp; [% group_name.$i %]<br/></div>
<div class = "td">&nbsp; [% group_desc.$i %]<br/></div>
<div class = "td">[% actv.$i %]<br/></div>
<div class = "td action" ><button type="button" onclick="edit(this);">edit</button>   </div>
<form>
[%-     SET i = i + 1;
END -%]
</div>
 </body>
</html>

我想編輯表的內容,並將其傳遞給cgi文件。 我已警告value1並發現,我編輯的值將在value1中。 我的要求是,我需要將這些值傳遞給cgi文件。

我在這行下面寫了一個像這樣的ajax調用,var value1 = jQuery(this).find(“INPUT”)。val();

ajax電話:

                  $.ajax({
                                    type: "GET",
                                    url : "process.cgi",
                                    data : {
                                            'value' : value1,
                                    },
                                    success : function(data) {
                                            alert("success");
                                    }

                            });

在我的cgi文件中,我試圖打印值,如,

 print $cgi->param("value");

但是,沒有值打印在那里。可能是什么問題?有人可以幫我解決這個問題嗎???

這里有許多不同的技術相互作用。 最好一次測試一次,看看問題出在哪里。

  1. 從命令行運行您的Perl程序,以確保它做正確的事情。
  2. 通過直接在瀏覽器中鍵入URL來運行Perl程序,以確保它正確地響應HTTP請求。
  3. 假定一個靜態HTML頁面調用您的Perl程序,以確保您以正確的格式傳遞正確的參數。
  4. 將jQuery和Ajax添加到HTML頁面中,以便它精確地重新創建您在第3階段中使用的靜態表單。

在確定每個階段都能正常工作之前,請不要進入下一階段。 只有一個非常糟糕的程序員才會嘗試同時調試所有這些技術。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM