0

我正在尝试在 ajax 中进行会话.. 因为我已经编写了这样的代码

BTLJ.ajax({
           type: "POST",
           url: btlOpt.BT_AJAX,
           data: datasubmit,
           success: function(html){
                //if html contain "Registration failed" is register fail
              BTLJ("#btl-register-in-process").hide();  
              if(html.indexOf('$error$')!= -1){
                  ...
                  ...
                  }
               }else{                  
                   BTLJ(".btl-formregistration").children("div").hide();
                   BTLJ("#btl-success").html(html); 
                   BTLJ("#btl-success").show(); 
                   alert(<?php session_start(); print_r($_SESSION); ?>);
                   setTimeout(function() { ); BTLJ(".kcregbox").show();},7000);
                  // BTLJ("#btl-success").hide();
               }
           },
           error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus + ': Ajax request failed');
           }
        });

但是如果我这样写的话,ajax 就不起作用了。请帮助我在 ajax 中进行会话。提前致谢。

4

2 回答 2

1

您在 Joomla 中的 AJAX 查询格式应如下所示。

           jQuery.post('index.php',{
                'option'        : 'com_componentname',
                'controller'    : 'controllername',
                'task'          : 'task_name',
                'format'        : 'raw',            
                'data'          :  data
            }).success(function(result) { 
                //if the request is success
            }).error(function() { 
                //if the request is fails
            });
于 2013-04-02T02:15:08.883 回答
1

我在 joomla 中将这种格式用于 ajax

$.ajax({
        type: 'GET',
        url: 'index.php', 
        data: {option: 'com_componenetname', task: 'taskname.youroperation', format: 'json', tmpl: 'raw'},
    dataType: 'json',
        async: true, // can be false also
        error: function(xhr, status, error) {
                console.log("AJAX ERROR in taskToggleSuceess: ")
                var err = eval("(" + xhr.responseText + ")");
                console.log(err.Message);
                },
        success: function(response){

                // on success do something
                // use response.valuname for server's data
                        }
                ,
        complete: function() {
            // stop waiting if necessary 
                 }                     
          });

在您的组件/控制器中,您应该有一个文件 yourcontroller.json.php 它将处理您的调用并返回编码的 json 数组将您在客户端中需要的所有数据

于 2013-05-12T03:42:44.283 回答