Symfony4 - isXmlHttpRequest showing wrong data - symfony

I'm not sure how to explain my problem.
I have a controller that has this piece of code to check if URL is accessed using ajax or not.
//check if ajax request
if ($request->isXmlHttpRequest()) {
...
} else {
...
}
If url is accessed using ajax it's returning JSON if not it's returning view.
When I access this URL in chrome it's showing right data(view) but if I move to for example google.com and click "back arrow" in Chrome's UI, it takes me back to my URL but now it's showing JSON.
Everything is working fine in Safari, so I'm not sure where is the problem and what to do...
Any ideas?
UPDATE: Same code works fine on Symfony 3.3

Fix: #Cache(vary={"X-Requested-With"})

Related

Differences between the results in Browser and HTML-View in Development-tools

I am working on a webapplication in asp.net mvc 5. I call a View from a action.
But this view is not displayed. In the developer-tools ( FF and Chrome) I can see a correkt answer in the html-Tab. But not in the browser.
Can anybody explain that?
Thats what is displayed:
Displayed
thats the answer in html-Tab of the dev-tools:
Answer
Many thanks for your help
P
Are you calling this Action / View via an AJAX call? Since you are using a Grid I would be inclined to think that is likely.
If so, you'll want to ensure that you are actually setting the results of your contents within the callback function :
// Call a controller action via an AJAX call
$.ajax('controller/action', { id: 42 }, function(results){
// results should be your actual View HTML
$('#result-area').html(results);
});
If you are using some type of third-party components for performing this, there should be some documentation for how to handle your callbacks from your Controllers.

uploading multiple photos in Firefox causes lost session in ASP.NET Web Forms

When We use Telerik UI for ASP.NET AJAX's telerik:RadAsyncUpload control to upload multiple photos (have preview before being uploaded), it works on all browsers in my local dev environment and our test server. It works on Chrome and IE in our beta and prod servers. But it doesn't work on Firefox in our beta and prod server; it kicks user out and redirect them to login page. We debugged into it and found the reason is that the session is lost. For some reason, Firefox will cause session lost.
Our beta and prod servers have load balancer while our test server doesn't. But even try individual ip address (not using domain name) in beta/prod, it still have the same problem.
Our code is based on the following link's sample code.
http://www.telerik.com/support/code-library/preview-image-before-it-have-been-uploaded-with-radasyncupload
I am not sure if this problem is related to Telerik control, or is it just a FireFox problem. It seems to me more like the latter.
This problem is really weird. It has been several weeks and we are still not able to solve it.
We have fixed the problem. The problem is still FireFox's bug, as indicated in that post
http://www.telerik.com/support/code-library/preview-image-before-it-have-been-uploaded-with-radasyncupload
The trick part is how to fix this bug: delay 10 ms before calling showThumbnail(...). Notice you cannot put the delay inside showThumbnail(...), that doesn't work.
window.CurrentFileUploaded = function (radAsyncUpload, args) {
...
if (navigator.userAgent.indexOf("Firefox") != -1) // if FireFox, delay 10 ms. This is the fix for FireFox bug!!!
{
setTimeout(function () { showThumbnail(...); }, 10);
}
else
{
showThumbnail(...);
}
}

GWT Formpanel POST issue

I am using GWT FormPanel to submit a POST request to a servlet which renders a pdf. The screen I am using to post have got a pop up with yes, no and preview button. yes and preview would open a pdf in new tab in browser.
The problem is when I use IE11 and clicks on preview it opens up a pdf well, I dont close the tab go back to previous screen and clicks yes, again request reaches to servlet but this time all the request parameters are null.
If the pdf tab is closed and then I click on yes it again works fine. This is an issue with IE11, works fine with Chrome. Any Ideas ?
If I change it to GET it works fine but I have a huge data that needs to be passed to servlet.
here is a code snippet :
formPanel.setBodyBorder(false);
formPanel.setBorders(false);
formPanel.setHeaderVisible(true);
formPanel.setAction(someURL+ "/someServlet");
formPanel.setMethod(Method.POST);
formPanel.setTarget("somePDF");
formPanel.setId("report");
HiddenField<String> hddnF = new HiddenField<String>();
hddnF.setName("Yogi");
hddnF.setValue("Value is set...");
formPanel.add(hddnF);
formPanel.submit();
Have overridden setTarget to show result(pdf) into new popup/tab
public native void setTarget(String target)/*-{
this.#com.extjs.gxt.ui.client.widget.form.FormPanel::setTarget(Ljava/lang/String;)(target);
}-*/;

IE9 refresh after Ajax request returns

I have a JavaScript class that displays a partially-opaque div over top of the content of another div when an Ajax request is sent to the server.
When the request returns, the JavaScript class hides the partially-opaque div....it works great...sort of.
Right now, in IE9, when the Ajax request is complete, the partial-opacity is only hidden if the user moves their mouse.
So, my question is, how do I force the browser to do what it's supposed to do?
This is my extremely simple function that is called after the request returns to the browser:
_hideBlockingDiv: function() {
if (this.get_blockingDivClientID()) {
var blockingElement = $get(this.get_blockingDivClientID());
if (blockingElement != null) {
blockingElement.style.display = 'none';
//I know that this method is executing correctly because I "hi" showed
//up properly...but the element remained visible:
blockingElement.innerHTML = 'hi';
}
//if I add the alert then everything works fine in IE9
//if I don't then the page will remain the same until the user moves their mose
//alert("done");
}
}
Please note that I am not using JQuery.
I am using the AJAX.NET library since I am a .NET developer (and JQuery didn't become popular until years after I implemented my Ajax-enabled server controls)
Thanks
-Frinny
How and where do you call the _hideBlockingDiv function from? Since you are using MS Ajax library, you might want to have a page loaded handler on client side and call this function from within that handler. So basically
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function(){
_hideBlockingDiv();
});
Hope this helps!
It turns out that the problem only exists in the beta version of IE9 that I was using at the time. This problem went away once the full version of IE9 was released.

How do I POST to a web page using Firebug?

How do I POST to a web page using Firebug?
You can send POST request to any page by opening console (e.g. in FireFox ctrl + shift + k) and typing simple JS:
var formPost = document.createElement('form');
formPost.method = 'POST';
formPost.action = 'https://www.google.com'; //or any location you want
document.body.appendChild(formPost);
formPost.submit();
AFAIK Firebug can't do this. However, there is a very useful Firefox extension, in the spirit of Firebug, called Tamper Data. This should be able to do what you want.
It allows you to monitor each request made by the browser, and you can turn on an option that allows you to look at, and edit, every single request before it gets sent.
Firefox 27 (maybe earlier versions too, never checked) has built-in developer tools to modify and resend requests. If you don't have Firebug installed, the console is available by pressing the F12 key. If Firebug is installed, press Ctrl+Shift+K instead.
I know this is an old question, but I recently stumbled upon the same problem and wanted to share the method I am using.
Assuming the web site you want to POST to has a form with method="POST" (a very likely scenario), you can use Firebug's JavaScript command line to programmatically submit a POST request. Just click the "Show Command Line" icon in Firebug and enter something like this in the narrow text box at the very bottom of the window:
document.forms[0].submit()
Maybe this helps someone.
Another simple solution is to load any webpage that uses jQuery, and type up a $.post() in the console.
HTTP resource test is a firefox plugin that can do this.
Another powerful Firefox plugin to perform post request and some more features is the Hackbar.
Related:
To resend a POST already made, right click the POST request in the Net/XHR view and click "Resend".
Using Firebug 1.12.0:
Got here looking for a Firebug way of doing this. Then I realized that I could use Fiddler. This is the most powerful tool I know when it comes to debugging web requests.
Fiddler The free web debugging proxy for any browser, system or
platform
Click the Composer tab and write your request as desired - then click Execute.
NO NEED of plugins !!
Just drag any url in BOOKMARK BAR, then right click and EDIT, and insert javascript code:
javascript:var my_params=prompt("Enter your parameters","var1=aaaa&var2=bbbbb"); var Target_LINK=prompt("Enter destination", location.href); function post(path, params) { var form = document.createElement("form"); form.setAttribute("method", "post"); form.setAttribute("action", path); for(var key in params) { if(params.hasOwnProperty(key)) { var hiddenField = document.createElement("input"); hiddenField.setAttribute("name", key); hiddenField.setAttribute("value", params[key]); form.appendChild(hiddenField); } } document.body.appendChild(form); form.submit(); } parsed_params={}; my_params.substr(1).split("&").forEach(function(item) {var s = item.split("="), k=s[0], v=s[1]; parsed_params[k] = v;}); post(Target_LINK, parsed_params); void(0);
then enter the target site-link, and click that button in BOOKMARK BAR! That's all!
( source: https://stackoverflow.com/a/38643171/2377343 )

Resources