Jump to content

Edit History

Estian

Estian

Good day - I can not for the life of me get an ajax call to work.

PrestaShop: 1.7.6.5
Module: CustomModule

Ajax URL:
https://domain/module/CustomModule/CustomModuleOrderManagerController?action=productStockIssue&id_product=###&id_order=###&ajax=true
(Context::getContext()->link->getModuleLink( 'CustomModule', 'CustomModuleOrderManagerController' ))
OR
https://domain/admin/index.php?controller=CustomModuleOrderManagerController&token=######?action=productStockIssue&id_product=###&id_order=###&ajax=true
(Context::getContext()->link->getAdminLink( 'CustomModuleOrderManagerController' ))

$.ajax( {
			type    : "GET",
			url     : link,
			data    : {
				ajax   : true,
				action : 'productStockIssue'
			},
			async   : true,
			cache   : false,
			beforeSend: function() {
				
			},
			complete: function() {
				
			},
			success: function( data ) {
				console.log( data );
			},
			error: function( XMLHttpRequest, textStatus, errorThrown ) {
				console.log( XMLHttpRequest );
				alert( XMLHttpRequest.responseText );
			}
		} );
class CustomModuleOrderManagerController extends ModuleAdminController {
	public function displayAjaxProductStockIssue() {
		$this->ajaxDie( Tools::jsonEncode( ['error' => 'This is a test.'] ) );
	}

	public function processProductStockIssue() {
		$this->ajaxDie( Tools::jsonEncode( ['error' => 'This is a test 2.'] ) );
	}

	public function ajaxProcessProductStockIssue() {
		$this->ajaxDie( Tools::jsonEncode( ['error' => 'This is a test 3.'] ) );
	}
}

Am I missing something? It just responds with "404 not found" with everything that I've tried.

Estian

Estian

Good day - I can not for the life of me get an ajax call to work.

PrestaShop: 1.7.6.5
Module: CustomModule

Ajax URL:
https://domain/module/CustomModule/CustomModuleOrderManagerController?action=productStockIssue&id_product=###&id_order=###&ajax=true
(Context::getContext()->link->getModuleLink( 'CustomModule', 'CustomModuleOrderManagerController' ))
OR
https://domain/admin/index.php?controller=CustomModuleOrderManagerController&token=######?action=productStockIssue&id_product=###&id_order=###&ajax=true
(Context::getContext()->link->getAdminLink( 'CustomModuleOrderManagerController' ))

class CustomModuleOrderManagerController extends ModuleAdminController {
	public function displayAjaxProductStockIssue() {
		$this->ajaxDie( Tools::jsonEncode( ['error' => 'This is a test.'] ) );
	}

	public function processProductStockIssue() {
		$this->ajaxDie( Tools::jsonEncode( ['error' => 'This is a test 2.'] ) );
	}

	public function ajaxProcessProductStockIssue() {
		$this->ajaxDie( Tools::jsonEncode( ['error' => 'This is a test 3.'] ) );
	}
}

Am I missing something? It just responds with "404 not found" with everything that I've tried.

Estian

Estian

Good day - 3 years later and I can not for the life of me get an ajax call to work.

PrestaShop: 1.7.6.5
Module: CustomModule

Ajax URL:
https://domain/module/CustomModule/CustomModuleOrderManagerController?action=productStockIssue&id_product=###&id_order=###&ajax=true
(Context::getContext()->link->getModuleLink( 'CustomModule', 'CustomModuleOrderManagerController' ))
OR
https://domain/admin/index.php?controller=CustomModuleOrderManagerController&token=######?action=productStockIssue&id_product=###&id_order=###&ajax=true
(Context::getContext()->link->getAdminLink( 'CustomModuleOrderManagerController' ))

class CustomModuleOrderManagerController extends ModuleAdminController {
	public function displayAjaxProductStockIssue() {
		$this->ajaxDie( Tools::jsonEncode( ['error' => 'This is a test.'] ) );
	}

	public function processProductStockIssue() {
		$this->ajaxDie( Tools::jsonEncode( ['error' => 'This is a test 2.'] ) );
	}

	public function ajaxProcessProductStockIssue() {
		$this->ajaxDie( Tools::jsonEncode( ['error' => 'This is a test 3.'] ) );
	}
}

Am I missing something? It just responds with "404 not found" with everything that I've tried.

×
×
  • Create New...