码迷,mamicode.com
首页 > Web开发 > 详细

Ecstore中如何调用发起Ajax请求

时间:2016-03-20 09:16:49      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:

Ecstore的JS框架使用了mootools,所以ajax调用也使用mootools中的Request组件。

语法:

var myRequest = new Request([options]);

参数:

  1. options - (object, 可选) 参见下列可选项

可选项:

  • url - (string: 默认为 null) 请求的目标URL
  • method - (string: 默认为 ‘post‘) HTTP请求方法, 可以是: ‘post‘ 或 ‘get‘
  • data - (string: 默认为 ‘‘) 为Request:send方法提供的默认请求参数
  • async - (boolean: 默认为 true) 如果为false, 则请求将以同步方式进行
  • encoding - (string: 默认为 "utf-8") 请求的编码方式
  • link - (string: 默认为 ignore) 可以为‘ignore‘, ‘cancel‘ 或 ‘chain‘
    • ‘ignore‘ - 当请求正在执行之中时,新的请求将被忽略
    • ‘cancel‘ - 当请求正在执行之中时,将立即取消当前执行中的请求,开始执行新的请求
    • ‘chain‘ - 当请求正在执行之中时,将会把新的请求链接在当前请求之后,依次执行所有请求
  • headers - (object) 请求头数据
  • isSuccess - (function) 可覆盖内置的isSuccess函数,可自定义请求成功的规则

看ecstore中的一个例子:

new Request({url:‘index.php?app=b2c&ctl=admin_specification&act=check_spec_value_id‘,
        onSuccess:function(re){
              if(re==‘can‘){
                  row.remove();
              }else{
                  MessageBox.error(re);
              }
        }
}).post(‘spec_value_id=‘+encodeURIComponent(specvid));

onSuccess是在ajax调用成功后返回,参数是响应内容ResponseText

Request还有两个扩展类:
Request.HTML 专门用于响应内容为HTML的请求,重要的参数有:
update - (element: 默认为 null) 请求响应的responseText要插入的目标元素
evalScripts - (boolean: 默认为 true) 如果为true, 则响应内容中script标签中的脚本内容将被执行
evalResponse - (boolean: 默认为 false) 如果为true, 则整个响应内容将被作为脚本来执行

Request.JSON 专门用于发送和接收JSON格式数据的请求,这里ajax调用后将返回一个json对像
示例:

var jsonRequest = new Request.JSON({
    url: "http://site.com/tellMeAge.php",
    onComplete: function(person, text){
        alert(person.age);    //显示 "25 years".
        alert(person.height); //显示 "170 cm".
        alert(person.weight); //显示 "120 kg".
    }
}).get({
    ‘firstName‘: ‘John‘,
    ‘lastName‘: ‘Doe‘
});

更多ecstore 问题可联系站长QQ 1611235299
技术分享

Ecstore中如何调用发起Ajax请求

标签:

原文地址:http://www.cnblogs.com/shopextool/p/5297117.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!