Last post Jan 12, 2019 03:33 PM by rubaiyat2009@gmail.com
Member
12 Points
16 Posts
Jan 12, 2019 03:19 PM|Robert John|LINK
Hi guys,
I'm new in mvc. I have faced problem with downloading
My Ajax code is
$.ajax({ type: "POST", url: base_url + '/Home/IndexSpecification', data: { option_id : 2 }, //dataType: 'json', encode: true, async: false, cache: false, success: function (data, status, jqXHR) { console.log(data); }, error: function (jqXHR, textStatus, errorThrown) { if (typeof (console) != 'undefined') { alert("oooppss"); } else { alert("error"); } } });
Downloading not working and not even returning any error. Anyone please help. Thanks!
All-Star
53031 Points
23611 Posts
Jan 12, 2019 03:32 PM|mgebhard|LINK
Robert John Hi guys, I'm new in mvc. I have faced problem with downloading My Ajax code is $.ajax({ type: "POST", url: base_url + '/Home/IndexSpecification', data: { option_id : 2 }, //dataType: 'json', encode: true, async: false, cache: false, success: function (data, status, jqXHR) { console.log(data); }, error: function (jqXHR, textStatus, errorThrown) { if (typeof (console) != 'undefined') { alert("oooppss"); } else { alert("error"); } } }); Downloading not working and not even returning any error. Anyone please help. Thanks!
The technique is to open a new window or iframe with a reference to the file to download. This is a very common situation and well documented with a Google search.
https://stackoverflow.com/questions/4545311/download-a-file-by-jquery-ajax
710 Points
113 Posts
Jan 12, 2019 03:33 PM|rubaiyat2009@gmail.com|LINK
Hi Robert,
In your ajax request in success block you have to write this code:
$.ajax({ type: "POST", url:'/Home/Download', data: { option_id: 2 }, //dataType: 'json', encode: true, async: false, cache: false, success: function (data, status, jqXHR) { window.location = '/Home/Download?option_id=2'; }, error: function (jqXHR, textStatus, errorThrown) { if (typeof (console) != 'undefined') { alert("oooppss"); } else { alert("something went wrong"); } } });
Hopefully, you got that you have to set your option id value globally and declare it in success section.
Please don't forget to mark as answer if it helps you. Thanks!
Member
12 Points
16 Posts
File downloading with Ajax problem
Jan 12, 2019 03:19 PM|Robert John|LINK
Hi guys,
I'm new in mvc. I have faced problem with downloading
My Ajax code is
Downloading not working and not even returning any error. Anyone please help. Thanks!
All-Star
53031 Points
23611 Posts
Re: File downloading with Ajax problem
Jan 12, 2019 03:32 PM|mgebhard|LINK
The technique is to open a new window or iframe with a reference to the file to download. This is a very common situation and well documented with a Google search.
https://stackoverflow.com/questions/4545311/download-a-file-by-jquery-ajax
Member
710 Points
113 Posts
Re: File downloading with Ajax problem
Jan 12, 2019 03:33 PM|rubaiyat2009@gmail.com|LINK
Hi Robert,
In your ajax request in success block you have to write this code:
Hopefully, you got that you have to set your option id value globally and declare it in success section.
Please don't forget to mark as answer if it helps you. Thanks!