6

I have been trying for 4 days to solve this problem. But I cannot return json data into a new tab page.

My code:

<script type="text/javascript">
function CustomerId() {

var url = "Home/PanelGoster";  // My URL

var veri = {
Id: Id.GetValue(),
};

$.ajax({
url: "/Home/PanelGoster",
type: "POST",
dataType: "json",
contentType: 'application/json',
data: JSON.stringify(veri),
success: function (mydata) {
if (mydata.error6 == true) {

}
else { // Success

var something = window.open(url, '_blank');  // Problem Here , it does not work
something.focus();   // Problem Here


("#MusterilerGetir").html(mydata);          // Problem Here, should be displayed in a new tab
}
},
error: function () {

}
});
return false;
}
</script>

Controller:

    public ActionResult PanelGoster(MyModel model)
    {
    var stringView = RenderRazorViewToString("PartialView", MyModel());
    return Json(stringView, JsonRequestBehavior.AllowGet);
    }
    }
user2418306
  • 2,352
  • 1
  • 22
  • 33
user2902180
  • 1,021
  • 3
  • 12
  • 12

1 Answers1

12

try

something = window.open("data:text/json," + encodeURIComponent(mysdata),
                       "_blank");
something.focus();

from Open a new tab/window and write something to it?

Community
  • 1
  • 1
Abu Romaïssae
  • 3,841
  • 5
  • 37
  • 59
  • I get error in new tab ....This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet. – user2902180 Oct 26 '13 at 13:35
  • I only see texts in new tab. I can not click nothing.So what do you recommend ? – user2902180 Oct 26 '13 at 13:42
  • 1
    it depends on what you need, in your question you said **Display json in new tab page** so I guess your question is answered, is it not ? – Abu Romaïssae Oct 26 '13 at 13:43
  • It should be `data:application/json,`, then it will be clickable. – Erik van Velzen Jul 27 '23 at 15:54