How or where are you calling it from? You can often add the '_blank' target to the window.open() method to open in a new window, however this is the default behavior so it should be working.
My all code works fine,if i use window.location.href = '@Url.Action("DSInvoice", "Report")' + '?salesId=' + msg.saleId; instead of
window.open('@Url.Action("DSInvoice", "Report")' + '?salesId=' + msg.saleId)
it works.
function OnSave() {
if (_lstProduct.length <= 0) {
ShowMessage("Failed to insert product", "No prducts found for save", "e");
}
else {
var arry = new Array();
var customerName = $('#CustomerName').val();
var address = $('#Address').val();
var contactNo = $('#ContactNo').val();
var salesDate = $('#salesDate').val();
for (var i = 0; i < _lstProduct.length; i++) {
arry[i] = _lstProduct[i][6] + ',' + _lstProduct[i][3] + ',' + _lstProduct[i][4]; //productid, quantity, price
}
$.ajax({
url: '@Url.Action("InsertDSalesProduct", "Sale")',
type: 'POST',
data: {
customerName: customerName,
address: address,
contactNo: contactNo,
salesDate: salesDate,
items: JSON.stringify(arry)
},
success: function (msg) {
if (msg.vmReturn.MessageType == 's') {
_lstProduct = new Array();
RenderTable();
$('#ProductId').val('');
ShowMessage('', 'Products sold successfully', 's');
window.open('@Url.Action("DSInvoice", "Report")' + '?salesId=' + msg.saleId)
}
elseif (msg.MessageType == 'e') {
ShowMessage('Failed to sale product', msg.Message, 'e');
}
},
error: function (msg) {
}
});
}
shakimran
Member
330 Points
149 Posts
window
Feb 01, 2013 11:37 AM|LINK
Hi,
after success of ajax call i want to show a report to a new window. this is my code. it will show on the same page, but i want it to a new page.
window.location.href = '@Url.Action("DSInvoice", "Report")' + '?salesId=' +saleId;
i also tried,
window.open('@Url.Action("DSInvoice", "Report")' + '?salesId=' +saleId)
but it doesn't work
Rion William...
All-Star
32154 Points
5234 Posts
Re: window
Feb 01, 2013 11:57 AM|LINK
Your second method should be working :
<script type='text/javascript'> var saleId = 1; window.open('@Url.Action("DSInvoice", "Report")' + '?salesId=' + saleId) </script>How or where are you calling it from? You can often add the '_blank' target to the window.open() method to open in a new window, however this is the default behavior so it should be working.
<script type='text/javascript'> var saleId = 1; window.open('@Url.Action("DSInvoice", "Report")' + '?salesId=' + saleId,"_blank") </script>Example
shakimran
Member
330 Points
149 Posts
Re: window
Feb 01, 2013 12:03 PM|LINK
Hi Rion,
I alredy did this. but not working and it show no error also. i checked it with firebug.
Rion William...
All-Star
32154 Points
5234 Posts
Re: window
Feb 01, 2013 12:08 PM|LINK
Can you post some additional code of how / where you are calling the Javascript from?
shakimran
Member
330 Points
149 Posts
Re: window
Feb 01, 2013 12:53 PM|LINK
Hi,
My all code works fine,if i use window.location.href = '@Url.Action("DSInvoice", "Report")' + '?salesId=' + msg.saleId; instead of window.open('@Url.Action("DSInvoice", "Report")' + '?salesId=' + msg.saleId) it works.
Rion William...
All-Star
32154 Points
5234 Posts
Re: window
Feb 01, 2013 01:01 PM|LINK
Try setting the asynx property of your AJAX call to false :
$.ajax({ url: '@Url.Action("InsertDSalesProduct", "Sale")', type: 'POST', async: false, data: { customerName: customerName, address: address, contactNo: contactNo, salesDate: salesDate, items: JSON.stringify(arry) }, success: function (msg) { if (msg.vmReturn.MessageType == 's') { _lstProduct = new Array(); RenderTable(); $('#ProductId').val(''); ShowMessage('', 'Products sold successfully', 's'); window.open('@Url.Action("DSInvoice", "Report")' + '?salesId=' + msg.saleId) } else if (msg.MessageType == 'e') { ShowMessage('Failed to sale product', msg.Message, 'e'); } }, error: function (msg) { } });If that doesn't work - you may consider creating a success variable and firing that after the ajax call is executed :
var successful = false; $.ajax({ url: '@Url.Action("InsertDSalesProduct", "Sale")', type: 'POST', async: false, data: { customerName: customerName, address: address, contactNo: contactNo, salesDate: salesDate, items: JSON.stringify(arry) }, success: function (msg) { if (msg.vmReturn.MessageType == 's') { _lstProduct = new Array(); RenderTable(); $('#ProductId').val(''); ShowMessage('', 'Products sold successfully', 's'); successful = true; //The operation was successful } else if (msg.MessageType == 'e') { ShowMessage('Failed to sale product', msg.Message, 'e'); } }, error: function (msg) { } }); //If the operation was successful - open the window if(successful) { window.open('@Url.Action("DSInvoice", "Report")' + '?salesId=' + msg.saleId); }Related Question
shakimran
Member
330 Points
149 Posts
Re: window
Feb 01, 2013 01:21 PM|LINK
Hi Rion,
It works. thank you very much.