小编asd*_*asd的帖子

json响应中的函数名称 - 不起作用

我试图在JSON响应中发送一个函数,并试图在js中提醒该函数.下面是代码.

JS:

$('input').keyup(function(){
    $.ajax({
        type: "POST",
        url: "sample.php",
        dataType : 'json',
        data: 'val='+$('input').val(),
        success: function(response){

         var json = transport.responseText.evalJSON();
         alert(json.function()); // => **should alert 'foo bar' - but not**
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

PHP:

<?php
// Our sample array
$foo = array(
  'string'  => 'bar',
  'function'=> 'function(){return "foo bar";}'
);
$value_arr = array();
$replace_keys = array();
foreach($foo as $key => &$value){
  // Look for values starting with 'function('
  if(strpos($value, 'function(')===0){
    // Store function string.
    $value_arr[] = $value;
    // Replace function string …
Run Code Online (Sandbox Code Playgroud)

php jquery json

2
推荐指数
1
解决办法
547
查看次数

输入框值未定义

当附加到div时,我得到输入框值为undefined.下面是代码.

JS:

$('#submitHook').click(function () {
    var v = ('#try').val();
    alert(v);
    $('#container').prepend('<tr><td>' + v + '</td></tr>');
});
Run Code Online (Sandbox Code Playgroud)

HTML:

<code>
<input type="text" id="try"></input>
<input type="button" id="submitHook"></input>

<table id="container></table>
</code>
Run Code Online (Sandbox Code Playgroud)

同样如何将其扩展到textarea?感谢任何帮助.

jquery

1
推荐指数
1
解决办法
2083
查看次数

标签 统计

jquery ×2

json ×1

php ×1