Ajax load a page like an include - ajax

I have a problem: I need to load a set of includes with ajax, but when I make the ajax
and request the current URL, I get the page url.
I have a problem when I call a page via ajax; the problem is when I try to get the request
URL in the page which is called with ajax, because it doesn't work like an include.
For example: I have my page "prueba.adp" and "prueba-ajax.adp"
The page prueba.adp calls via ajax to prueba-ajax.adp.
So when I try to get the request URL in prueba-ajax.adp I get prueba-ajax.adp, but
if I set an include I get prueba.adp.
Do you know any way to execute the ajax page and get the request url of the page which made the ajax call?

Related

Can't add cookies to ajax page JSP

I'm developing a simple JSP page with a div updated via AJAX XMLHttpRequest object
When I try to use (response.addCookies(String,String)) I get no errors but the page stops loading and there are no output whatsoever...
Are there no way I can add cookies through an Ajax request object???

Scala Play - calling controller method from view doesn't load a new page

I display information, gather some user's input, and call a controller method using ajax/java script call from the view. However, instead of displaying a new/different html page, the controller method returns back to the original html page that I called jscript from.
Is this because of ajax call? How do I make sure that controller method would display the html file it's supposed to, instead of staying on old html page?
It sounds to me like what you want to do is to open a different url than the one you are on. To do that you do not use ajax. Instead try using javascript to change window.location to tell the browser to go to the url (or 'call your controller'). It looks like this:
window.location.assign("/your/controller/url"); // or
window.location = "/your/controller/url";
There is more to read about it here: https://developer.mozilla.org/en-US/docs/Web/API/Window.location
You can think of ajax as a separate little browser that lets you call the web server but letting you handle what comes back with javascript rather than always showing it to the user. So if you want to do the call with ajax but get the response HTML into your page, you are responsible for taking that response and inserting it into the DOM.

Refresh div (Wordpress comments) with ajax

What I'd like to do is have a button that you can click to refresh the comments section without reloading the page.
This seems like it should be simple to do, but I just can't get my head around Ajax.
(no button just yet, just an interval)
setInterval(function(){
$(".commentswrapper").load("html");
}, 10000);
Failed to load resource: the server responded with a status of 404 (Not Found)
localhost:8888/post-title/html
(http:// omitted from link because SO won't let me wrap it in code tags or post it otherwise)
Shouldn't that just refresh the html of that div?
The jquery load method requests a page of HTML and puts it in your div. the parameter you give is a URL from your server. In your example, it is requesting a URL of "HTML", which doesn't exist in Wordpress.
To get this working, you would have to write a new server script, e.g. Getcomments.php which returns the comments for the current page.
This isn't trivial unless you've done some server side programming in php and are familiar with the Wordpress codex,

CakePHP redirect entire page instead of div

When I'm logging in with my CakePHP login function in the Users controller using ajax. The errors will be displayed in an Div above the login form. But when I have a successful login, I want to redirect the page to the homepage. When I'm using $this->redirect('home'); in the Users controller, the Div will only be updated.
How can I make sure that the entire page will be reloaded? I rather fix this problem with PHP than Javascript 'cause I'm using the Writebuffer method with the JSHelper.
Thanks!
This should be solved in client side. Because client browser gets the AJAX response and puts the output inside the DIV.
Although you can embed javascript code inside the AJAX response. For example, if login is incorrect, then put a window.location javascript code inside the output. But this is not a good solution.
Return an HTTP status code within AJAX response. If for example code is 401, then redirect.
if (data == '401') {
document.location.href="http://example.com";
}

Ajax request returns a 404 but URL works fine

I'm doing an jQuery ajax call to an XML page in my CakePHP site. For some strange reason CakePHP returns a 404 error when I do an ajax call, yet there is no problem going to the URL directly at http://imgfave.com/gragland/rss.
You can see the issue by clicking the link on my test page: http://imgfave.com/ajaxtest
The error page says: "The requested address '/gragland/rss' was not found on this server".
Why would CakePHP have a problem returning the page only when fetched via ajax?
According to FireBug, the main difference between the requests is:
X-Requested-With XMLHttpRequest
From AJAX request.
P.S.: After a quick test using the same headers, it retrieves the RSS without error
Make sure you have a view file. An html request will return without error without a view. But AJAX request returns 404.

Resources