Codeigniter form post url not reaching routes.php - codeigniter

One of my forms with a POST method is doing something weird. When I submit the form it sends the form url to the browser URL box and it doesn't hit the controller. What is causing this? I'm getting this only for one of my form and I've double checked and triple checked my routes.php file, my controller, etc.

Related

How to submit a form using codeigniter without changing the url?

I'm Unable to submit the form within the same page and getting result in the same page.
Put in the action of the your form the current URL.
action="<?php echo current_url();?>"
You probably need
redirect('controllerName')
So once you send data from the form to the controller, that controller does the processing and then redirects back to the index().
Use Ajax and Javascript to submit form without changing the url.

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";
}

Spring with AJAX integration

So I'm able to successfully integrate AJAX requests with Spring MVC. However, I have a problem- if I click the "submit" button of my form, my #Controller class detects the url and returns a ModelAndView. However, what I want is that there be an AJAX check first, and if the form submission is not successful (e.g., blank fields), return an AJAX response. Otherwise, proceed as per normal and display a ModelAndView. However, I have no clue how to integrate both at the same time.
Any ideas or tutorials are appreciated.
Thanks!
You have several choices:
submit the form to a specific, different URL, when using AJAX
add a specific parameter to the request when posting using AJAX, and use this specific parameter to check if the request is n AJAX request
test if the X-Requested-With request header is present and contains XMLHttpRequest
I would go the PJAX route or what's also known as HiJax.
Basically you return a subset of the page if it's an AJAX request using headers. Most people than just use conditions in their view/template to decide to include the full or chrome-less HTML.

Ajax load a page like an include

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?

What causes Firefox to make a GET request after submitting a form via the POST method?

What causes Firefox to follow a POST request with a GET request when submitting a form via the POST method? The GET method is sent to the same url as the POST method but without the request parameters.
If you change the form method to GET, it will result in two identical GET requests.
This is a bug in Firefox 3. This happens when the response to the POST contains an image tag with an empty source attribute. eg <img src=""/>
The URL POSTed to might be returning a Redirect -- that would cause a GET. This is commonly done so that the page can be refreshed without reposting.
Probably there is some javascript involved. The form is submitted as a result of an onclick event in an anchor with: href="..." onclick="..form.submit()"

Resources