3

I have a jquery.ajax object in which I want to substitute xhr. However executing the following code gives me an error:

TypeError: Property 'xhr' of object #<Object> is not a function

The relevant code is:

    var req = jQuery.ajaxSettings.xhr();
    req.upload.addEventListener('progress', calendar.check_progress, false);

    $.ajax({
        url: script_root + '_save_file/'+id+'/'+timestamp,
        type: 'POST',
        processData: false,
        contentType: false,
        data: fd,
        xhr: req,
        success: function(data){
            do_something();
        },
        error: function(data){
            console.log(data);
            do_something_else();
        }
    });

Grouping with xslt and child nodes

I have tried some of the examples here, but I still can't get the correct output. I haven't worked much with XSLT before. I want to group on the "Detail" element and get all the "Data" elements matching that group as children to the "Detail" element.

Example:

input

<?xml version="1.0" encoding="utf-8"?>
<File>
  <Detail type="A" group="1" >
    <Data>
      <Nr>1</Nr>
    </Data>
    <Data>
      <Nr>2</Nr>
    </Data>
  </Detail>
  <Detail type="B" group="1">
    <Data>
      <Nr>3</Nr>
    </Data>
    <Data>
      <Nr>4</Nr>
    </Data>
  </Detail>
  <Detail type="B" group="2">
    <Data>
      <Nr>5</Nr>
    </Data>
  </Detail>
  <Detail type="A" group="1">
    <Data>
      <Nr>6</Nr>
    </Data>
  </Detail>
</File>

Wanted output ("Detail type="A" group="1"> elements grouped together and all the elements matching that group as children)

<?xml version="1.0" encoding="utf-8"?>
<File>
  <Detail type="A" group="1" >
    <Data>
      <Nr>1</Nr>
    </Data>
    <Data>
      <Nr>2</Nr>
    </Data>
    <Data>
      <Nr>6</Nr>
    </Data>
  </Detail>
  <Detail type="B" group="1">
    <Data>
      <Nr>3</Nr>
    </Data>
    <Data>
      <Nr>4</Nr>
    </Data>
  </Detail>
  <Detail type="B" group="2">
    <Data>
      <Nr>5</Nr>
    </Data>
  </Detail>
</File>

Thanks for help :)

4

1 回答 1

2

xhr以其他方式使用。请参阅文档:http ://api.jquery.com/jQuery.ajax/

xhr: 函数

默认值:ActiveXObject 可用时 (IE),否则为 XMLHttpRequest

创建 XMLHttpRequest 对象的回调。可用时默认为 ActiveXObject (IE),否则为 XMLHttpRequest。重写以提供您自己的 XMLHttpRequest 实现或对工厂的增强。

可能是你正在寻找类似的东西

xhr: function() {
    var xhr = $.ajaxSettings.xhr();
    xhr.upload.addEventListener('progress', calendar.check_progress, false);
    return myXhr;
},
于 2012-09-11T16:51:02.090 回答