I guess I'm just having difficulty with $.post... I've used it successfully in the past, but I have to be forgetting something important. All I want is a "hello world", but I'm getting a complicated object. I am befuddled.

我想我只是对$.post有困难。我曾经成功地使用过它,但我不得不忘记一些重要的东西。我只想要一个“你好世界”,但我得到了一个复杂的对象。我糊里糊涂的。

var_test.php

var_test.php

<?php
    PRINT "hi";
?>

index.html

index . html

<!doctype html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<html><head>
    var thing = $.post( "var_test.php");
    console.log(thing);
</head><body></body></html>

console output

控制台输出

Object { readyState: 1, getResponseHeader: .ajax/v.getResponseHeader(), getAllResponseHeaders: .ajax/v.getAllResponseHeaders(), setRequestHeader: .ajax/v.setRequestHeader(), overrideMimeType: .ajax/v.overrideMimeType(), statusCode: .ajax/v.statusCode(), abort: .ajax/v.abort(), state: .Deferred/d.state(), always: .Deferred/d.always(), then: .Deferred/d.then(), 8 more… }

3 个解决方案

#1


1

You should add a callback instead that receives the response/data from your php:

您应该添加一个回调函数来接收来自php的响应/数据:

$.post( "var_test.php", function(response) {
    console.log(response);
});

That callback will be executed once the request has finished, that way, you can be sure that you will have your data ready and set to use it in your JS.

该回调将在请求完成后执行,这样,您就可以确保准备好数据并将其设置为在JS中使用。

更多相关文章

  1. 开发学习Jquery实例---双击表格弹出模态对话框,编辑提交数据
  2. 执行Django数据库值的计算:视图。py或Javascript模板吗?
  3. jquery 如何获取json指定键为指定值的另一个指定键的值,该值还是
  4. Jquery 传json格式数据到后台,后台反序列化得到一个集合list
  5. JQuery.AJAX - 我的服务器可以返回一大块数据吗?
  6. jQuery向服务器请求数据并处理
  7. jquery datatables-一个数据表中的最大列数
  8. 前台jquery+ajax向后台请求数据,后台返回json,前台显示
  9. 使用js和ajax从django服务器检索数据

随机推荐

  1. 【第808期】你不懂JS:ES6与未来 语法(中)
  2. 【第417期】记忆前端早读课
  3. 2021-1-18
  4. 活动|坚持21天阅读分享
  5. 【招聘】杭州尚妆网招前端
  6. 【招聘】杭州上海蚂蚁金服招前端
  7. 专访|腾讯微信支付设计中心重构负责人@Gho
  8. 【招聘】广州百田招前端
  9. 数据库中间件 Sharding-JDBC 源码分析 —
  10. 招聘|北京字节跳动科技有限公司