函数中未使用ajax返回值

时间:2018-07-19 17:01:58

标签: php jquery json ajax

index.php

$(function () {
  $('form').on('submit', function (e) {
    e.preventDefault();
    $.ajax({
        type: 'post',
        url: 'sort.php',
        data: $('form').serialize(),
        success: function (response) {
        $("#hoverdemo").dotHover(response, { img: '665.png' });
        }
      });
    });
  });

sort.php

$array=[{ x: 28100, y: 48500, text: 'A' },{ x: 28100, y: 48500, text:'A' }];
echo $array;

将$数组的值从另一页复制并粘贴到split:S

时,响应正在运行

2 个答案:

答案 0 :(得分:3)

您需要发送json而不回显数组本身。

2018-07-19 17:52:32.393711: W tensorflow/core/framework/op_kernel.cc:1273] OP_REQUIRES failed at training_ops.cc:2507 : Internal: Invalid variable reference. Traceback (most recent call last): File "debugging_jules_usage.py", line 391, in <module> mainLoop() File "debugging_jules_usage.py", line 370, in mainLoop raise e File "debugging_jules_usage.py", line 330, in mainLoop Kn.fit(train) File "/home/jbayet/xai-link-prediction/xai_lp/temporal/models_temporal.py", line 707, in fit self._train_one_batch(X_bis, i) File "/home/jbayet/xai-link-prediction/xai_lp/temporal/models_temporal.py", line 639, in _train_one_batch self.optimizer.minimize(batch_model_loss, global_step=tf.train.get_global_step()) File "/home/jbayet/miniconda3/envs/xai/lib/python3.6/site-packages/tensorflow/python/training/optimizer.py", line 409, in minimize name=name) File "/home/jbayet/miniconda3/envs/xai/lib/python3.6/site-packages/tensorflow/python/training/optimizer.py", line 564, in apply_gradients update_ops.append(processor.update_op(self, grad)) File "/home/jbayet/miniconda3/envs/xai/lib/python3.6/site-packages/tensorflow/python/training/optimizer.py", line 161, in update_op update_op = optimizer._resource_apply_dense(g, self._v) File "/home/jbayet/miniconda3/envs/xai/lib/python3.6/site-packages/tensorflow/python/training/adam.py", line 166, in _resource_apply_dense grad, use_locking=self._use_locking) File "/home/jbayet/miniconda3/envs/xai/lib/python3.6/site-packages/tensorflow/python/training/gen_training_ops.py", line 1105, in resource_apply_adam _six.raise_from(_core._status_to_exception(e.code, message), None) File "<string>", line 3, in raise_from tensorflow.python.framework.errors_impl.InternalError: Invalid variable reference. [Op:ResourceApplyAdam] 更改为echo $array;

php数组的语法也应为:

echo json_encode($array);

然后将$array = [ ['x' => 28100, 'y' => 48500, 'text' => 'A'], ['x' => 28100, 'y' => 48500, 'text' => 'A'] ]; // OR $array = array( array('x' => 28100, 'y' => 48500, 'text' => 'A'), array('x' => 28100, 'y' => 48500, 'text' => 'A') ); 添加到dataType:'json'选项中,以便将json字符串解析为成功回调内的javascript数组

答案 1 :(得分:-1)

      $(function () {
  $('form').on('submit', function (e) {
    e.preventDefault();
    $.ajax({
        type: 'post',
        url: 'sort.php',
        dataType:'json',
        data: $('form').serialize(),
        success: function (response) {
        $("#hoverdemo").dotHover(response, { img: '665.png' });
        }
      });
    });
  });

对php进行排序

 <?php  

$ array = [{x:28100,y:48500,文本:'A'},{x:28100,y:48500,文本:'A'}];

echo json_encode($ array); ?>

不起作用:(