开发者

i ajax a file with jquery,and i don't know where does it download to

开发者 https://www.devze.com 2022-12-16 16:30 出处:网络
$.ajax({ type:开发者_StackOverflow社区 \"POST\", url: \"http://images.digu.com/web_res_v1/images/logo.png?t=20091230\",
$.ajax({
 type:开发者_StackOverflow社区 "POST",
 url: "http://images.digu.com/web_res_v1/images/logo.png?t=20091230",
 success: function(msg){ alert( "Data Saved: " +   msg ); } 
}); 

where is the download file.

thanks


AJAX request actually only 'download' the requested resource into your browser memory. If you request an image like in your code, the image will be put into browser's cache. So if you set an img DOM element's src with the same URL, the modern browser will smart enough to use the one in cache.

If you request a part of web page, not an image like your code above, you can insert it directly into DOM element:

$.get(URL,
  {},
  function(data){
    $("#container").html(data);
  });

Read the jQuery documentation about AJAX for more example and explaination.

Btw, AJAX request can be only made to the same domain, so make sure that you only request URL in the same domain with your jQuery code. Your code above will only work if the page also in http://images.digu.com/.

Second note, use POST when you need to send data that will change something in the server side (add, edit, delete). If you just want to request something, use GET. Also, if you don't need extra AJAX setting, I recomend you to use $.post(); and $.get(); so the code will be more readable and easier to maintain, at least it work for me :)


It is loaded into browser memory, and likely your cache. If you're wanting to save the file, you probably don't want AJAX.


It doesn't download to a file or anything. A successful ajax call returns data in a javascript variable. In this case you are saving it into a variable called msg. Depending on your app, you could insert this data into the webpage (i.e into the DOM).


I guess I'd ask for more detail. It seems like you just want to set an image's src property on the fly since I don't see you posting any data. To do that, you can use something like this:

$("#my_image").attr("src","http://images.digu.com/web_res_v1/images/logo.png?t=20091230"); 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号