Click here to Skip to main content
15,885,748 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is the JavaScript code to send request
JavaScript
$.ajax({url: "/"+ controller +"/"+ action+"/", type: 'POST', dataType: 'html', data: parameter, contentType:"html", timeout: 90000, success: container, error:function (xhr, ajaxOptions, thrownError){
if(xhr.status==404){
alert(ajaxOptions);
}}});



controller: Customer
action: add

here is my init function in CustomerController class
PHP
public function init()
{        
	$ajaxContext = $this->_helper->getHelper('AjaxContext');
	$ajaxContext->addActionContext('add', 'html');
	$ajaxContext->initContext();
}

public function addAction()
{
	// $this->_helper->layout()->disableLayout(); 
	// $this->_helper->viewRenderer->setNoRender(true);
}



Now, page is always getting 404 error. What am I missing?

I am using zend framework 1.12.4
Posted
Updated 4-Aug-14 23:15pm
v3

1 solution

I have solved the problem. The solution I found somewhere on the web.

In all the other suggestion they were suggesting to add switch context as below:
PHP
$contextSwitch=$this->_helper->getHelper("contextSwitch");
$contextSwitch->addActionContext("addnewcustomer","html");
$contextSwitch->initContext();


But I didn't add the view file, which was suppose to be:
addcustomer.html.phtml

That is why the error 404 was showing.

But after I had added the file new error 500 was showing. After searching two days finally I found a solution. The problem was, xml or json get accepted easily but html context, probably, does not exists. So needed to be created before added. Here is the complete added code:

PHP
$contextSwitch=$this->_helper->getHelper("contextSwitch");
$contextSwitch->setContext('html', array('suffix'=> 'html','headers'=> array('Content-Type' => 'text/html; Charset=UTF-8',),));
$contextSwitch->addActionContext("addnewcustomer","html");
$contextSwitch->initContext();


and the required view file is
addnewcustomer.phtml

the problem solved right away
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900