2013-02-27 70 views
1

我正在尝试使用jquery .ajax {type:get},并且我无法弄清楚成功函数是如何工作的,但文档并没有为我裁剪。jquery成功概念

  1. 当我阿贾克斯{}获得不page.php文件从page.php文件
  2. 什么是变量/函数使用,在jQuery中,获得GET数据(我在想什么抢码以PHP $ _get的形式)
  3. 当我从page.php获取数据时,它将以完整的HTML格式并准备好应用于页面。我需要做的只是发布在现有数据下。我会在DIV上使用.appendto()吗?我想粘贴HTML内容?

你也知道任何好的jquery书吗?不知何故,我只知道我会一直使用这个,我也可以学习它。

+0

jQuery将得到'page.php'产生的文本。任何“回声”都是被读取的。 – zzzzBov 2013-02-27 05:02:13

回答

2

阿贾克斯的正确语法如下:

jQuery.ajax({ 
      url: "", //here you need to give the full path of the URL. 
      cache: true/false, //choose any one true if you want to enable the cache. 
      type: "get/post", // any type which you want to choose to post the data. 
      dataType: "text/html/json/jsonp/xml", //In your case choose the html. 
      success: function(returnData){ 
       //here the returnData will be data that you print in file given in URL. 
       alert(returnData); 
       $(".someDiv").append(returnData); //To answer #3 
      }, 
      error: function(a,b,c){ 
       //call when any error occur. 
      } 
    }); 

我希望这将有助于你。

+0

谢谢,现在有道理! – Rujikin 2013-02-27 05:58:06

2

在成功函数

$.ajax({ success : function(retrunValues) { alert(retrunValues); } });

从你后台页面,您可以得到任何数据。像任何查询或任何事物的结果一样检查这一点。

所以从PHP页面这个数据将在success function。那么你怎么样去使用它,你可以使用它的retrunValue

+0

谢谢,现在有道理! – Rujikin 2013-02-27 06:00:01

+0

不客气 – 2013-02-28 17:05:56