Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.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
Javascript php-获取动态java脚本代码的函数_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript php-获取动态java脚本代码的函数

Javascript php-获取动态java脚本代码的函数,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我有一个javascript函数,可以根据用户输入生成动态代码 现在我有一个表,其中一列是一个多下拉选择框 下拉列表的值来自php地址 如何使下拉列表以动态方式与表的其余部分一起生成 p、 美国。 我知道我想用一个get ajax函数来获取它,但我不会发送任何值,只是从数据库中获取它们。所以任何一个例子都是很好的 这是我的代码: $(document).ready(function() { $("#submit").click(function(e) { $("#Table").

我有一个javascript函数,可以根据用户输入生成动态代码

现在我有一个表,其中一列是一个多下拉选择框

下拉列表的值来自php地址

如何使下拉列表以动态方式与表的其余部分一起生成

p、 美国。 我知道我想用一个get ajax函数来获取它,但我不会发送任何值,只是从数据库中获取它们。所以任何一个例子都是很好的

这是我的代码:

$(document).ready(function() {

  $("#submit").click(function(e) {

    $("#Table").empty();
    //myCall();
    e.preventDefault();
    if($("#NumOfLevels").val() >0) {
      var size = $("#NumOfLevels").val();
      var str='';
      var values = '<$php do {  $> <option value="<$php echo $row_rsCatalog["CatalogName"]$>"> <$php echo $row_rsCatalog["CatalogName"]$></option><$php } while ($row_rsCatalog = mysql_fetch_assoc($rsCatalog));$rows = mysql_num_rows($rsCatalog);if($rows > 0) { mysql_data_seek($rsCatalog, 0);$row_rsCatalog = mysql_fetch_assoc($rsCatalog);}$>';
      str+='<table align="center" width="694" border="0" cellspacing="3"  cellpadding="0">';
      str+='<tr><th style="width:auto" scope="col">Level </th><th width="107">Score</th><th width="58">File</th><th width="80">Link</th><th width="93">StartDate</th><th width="85">EndDate</th></tr>';


      for(var i = 0; i< size ; i++) {
        str+='<tr><td id="stage'+i+'" style="width:auto">no.  '+(i+1)+'</td><td><span id="sprytextfield4"><input type="text"  name="Score" id="Score"/>';
        str+='<span class="textfieldRequiredMsg">A value is required.</span></span></td>';
        str+='<td><input type="file" name="gameFile" id="gameFile" /></td>';
        str+='<td><select multiple="multiple" name="CatlogLink" id="CatlogLink">';
        str+=values;
        str+='</select></td>';
        str+='<td><input type="text" class="date" id="datepicker" ></td>';
        str+='<td><input type="text" class="date" id="datepicker2" "></td>';
        //str.find('input').datepicker();
      }

      //str+='</tr></table>';

      $("#Table").append(str);
      var btn = '';
      btn+='<tr><td width="192" colspan="2" align="center"><input type="submit" name="Submit" id="submit" value="שליחה"/></td>';
      btn+='<td width="309" colspan="4" align="center"><input type="reset" name="reset" id="Clear" value="ניקוי" /></td></tr></tr></table>';
      $("#Table tr:last").after(btn);


    }
    $(".date").click(function() {
      $( ".date" ).datepicker();
      $( ".date" ).datepicker();
    });

  });
});

我不明白您应该如何使用jquery创建php源代码?一个是在web服务器上解释的,另一个是在浏览器加载的源实例中动态生成的,但是如果没有web服务器来解释服务器端脚本,这对您没有多大帮助。。。除了显示你的页面应该如何工作,从而暴露它的恶意访问企图,这将是一堆源浏览器会简单地显示或跳过,但不会解释为php


当然,我可能不理解您在这里想要实现什么,但我可能会弄错,但在我看来,这就是它的样子。

我建议您进行调查。您仍然应该使用ajax get或getJSON来使用php从数据库中获取数据

一个非常简单的例子:

script.js

function.php

在script.js的成功函数中,响应如下所示:

{
    "data": [
        {
            "id": 1
        },
        {
            "id": 2
        }
    ]
}
此时,您可以循环使用response.data,因为它将是构建下拉列表或其他HTML元素的数组

我可以在这里补充一点,您应该避免在javascript代码中使用PHP代码,因为事情可能会变得非常混乱。最好将js文件中的javascript和PHP文件中的PHP分开

// If you send data in the above ajax call, it can be retrieved through $_GET
// EG
// data: {test:"hello world"} would be retrieved
// at $_GET['test'] and contain the string "hello world"

// Query and retrieve data from your database
$data = array(
    array('id' => 1),
    array('id' => 2) // and so on...
);
// $response should be some kind of array (that way json_encode won't error out)
$response = array('data' => $data);

echo json_encode($response); // Will output a json encoded string so that the ajax call can decipher it
exit; // This would exit the script, so anything after this statement won't run.
// Note: If you echo anything after the json_encode then the ajax call won't be able to decipher the response.
{
    "data": [
        {
            "id": 1
        },
        {
            "id": 2
        }
    ]
}