开发者

jQuery that do document.location = "url"

jQuery have many features for ajax requests, but if i want to download the response from the server the browser is not showing the download dialog if i do it using $.a开发者_StackOverflow中文版jax

This works just fine:

document.location = 'VCard.aspx?name=Andreas'

In my responce from the server a set these to headers:

Response.ContentType = "text/x-vcard";
Response.AddHeader("content-disposition", "attachment; filename=vcard.vcf");

But if i do like this the download dialog don't show, the download works but the dialog don't show.

$.ajax
({
    type: "POST",
    url: '/VCard.aspx',
    data: { name: 'Andreas' }
});

My data: contains of more then 40 different parameters and i want to use the json syntax to build the arguments to make it clear.


$.ajax will use an XMLHttpRequest object to post the data. This will not trigger browser UI, since it's expected that it will be scripted.

If you just want a properly formatted querystring from an object, you can use $.param.


The $.ajax method is used to get data back from your server not show a dialog. You can have the ajax method show a dialog by doing something in the success action

$.ajax({
   type: POST,
   url: '/VCard.aspx’,
   data: { name: 'Andreas' }, 
   success: function (data, textStatus, jqXHR) {
     /*open your dialog*/
   }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜