0

I need to make AJAX request for HTML content, but when I look into firebug it seems that request is downloading media files attached to requested html (images, CSS). How can I stop it? I need only plain text from PHP-genereted HTML.

$.ajax({
    type:     'GET',
    url:      'http://examplehost.com,
    dataType: 'text',
    cache: false,
    success:  function (data) {
        // SUCCESS CODE HERE
    },
    error:    function (xhr, type, error) {
        // ERROR CODE HERE
    },
    complete: function() {
        // ON COMPLETE CODE HERE
    }
});

I also must have possibility to run functions when request is complete! Im using ZEPTO library, but its JQuery clone, so the functions are similar.

Artur Czyżewski
  • 705
  • 5
  • 12
  • 1
    Are you trying to get contents from another domain? Did you try just to use `$.get`? Are you appending the content to a DOM element (then it will of course download all the assets.)? – m90 Sep 27 '12 at 10:09
  • According to ZEPTO documentation, $.get function have no "complete" callback. Im manipulating the data which I retrieve with zepto ( $(data).find(... ), not appending html contents to my html itself. Im building an array with data fetched from AJAX. Im getting contents from another domain. – Artur Czyżewski Sep 27 '12 at 16:11
  • Do you really need the complete callback (in addition to success)? Also, you shouldn't be able to get HTML via AJAX from a remote domain unless you are using CORS. – m90 Sep 27 '12 at 17:13
  • I have PHP "proxy" for that, with header "allow-origin-domain", so the request is possible. When im debuging in firebug i can see in "network" panel that the files i mentioned are beeing download when the request for html is send... – Artur Czyżewski Sep 28 '12 at 09:27
  • Then I'd guess that you are somehow appending this HTML to the DOM? – m90 Sep 28 '12 at 09:28
  • No, im loading data to variable, and then traversing through elements to find what I need, but im not adding that data to currently displeyed page. I dont know how to explain that. Im doing it like this -> var mydata = $(data).find('#someid').html(); and thats it. Im not appending the contents of html to DOM of my page... – Artur Czyżewski Oct 02 '12 at 17:36
  • You are right, apparently the wrapping (`$(data)`) makes the browser download the data, see this fiddle: http://jsfiddle.net/Z5VN8/ and check what happens when you uncomment the wrapping. – m90 Oct 03 '12 at 08:18
  • See: https://github.com/madrobby/zepto/blob/master/src/zepto.js#L156 and https://github.com/madrobby/zepto/blob/master/src/zepto.js#L101 for what's happening – m90 Oct 03 '12 at 08:29
  • Uncommenting line with variable set results in sending GET request... So... Any idea how to stop this and retive only plain html text? – Artur Czyżewski Oct 07 '12 at 14:27
  • You need to process your data without the help of our beloved $ I guess (using plain String processing) as everything else will result in the creation of a DOM Element and the download of files. Do you have any influence on what's happening Server-side? – m90 Oct 07 '12 at 14:42

0 Answers0