信息发送来回AJAX [英] sending information back and forth with AJAX

查看:114
本文介绍了信息发送来回AJAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用$。员额,你可以当你需要从服务器接收信息,将信息发送到服务器,但什么?

With $.post, you can send information to the server, but what when you need to receive information from the server?

如何被,可以由一个PHP变量举行是的,可以通过持有一种方式做信息变更的JavaScript变量,反之亦然?

How does information change from being of a way that can be held by a php variable to being of a way that can be held by a javascript variable and vice-versa?

推荐答案

这是更切合你的问题:的 http://docs.jquery.com/Ajax/jQuery.post

This is more relevant to your question: http://docs.jquery.com/Ajax/jQuery.post

从请求test.php的(HTML或XML,这取决于返回)通知了结果。

Alert out the results from requesting test.php (HTML or XML, depending on what was returned).

$.post("test.php", function(data){
  alert("Data Loaded: " + data);
});

通知从请求test.php的结果与数据的附加有效载荷(HTML或XML,根据什么被返回)。

Alert out the results from requesting test.php with an additional payload of data (HTML or XML, depending on what was returned).

$.post("test.php", { name: "John", time: "2pm" },
  function(data){
    alert("Data Loaded: " + data);
  });

获取test.php的网页内容,将其存储在XMLHtt presponse对象和应用程序()JavaScript函数。

Gets the test.php page content, store it in a XMLHttpResponse object and applies the process() JavaScript function.

$.post("test.php", { name: "John", time: "2pm" },
  function(data){
    process(data);
  }, "xml");

获得已JSON格式(约翰福音,时间=>2:00))被返回的test.php的页面内容; ?>)

Gets the test.php page contents which has been returned in json format ("John","time"=>"2pm")); ?>)

$.post("test.php", { func: "getNameAndTime" },
  function(data){
    alert(data.name); // John
    console.log(data.time); //  2pm
  }, "json");

这篇关于信息发送来回AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆