How to link to presenter methods from js file

Notice: This thread is very old.
Timon
Member | 4
+
0
-

Hello,
I have a form that calculates rates using ajax. When the user selects a select option, the rates for that selection are retrieved from the database using angular and ajax. The angular js file that calls the function in the presenter in in www folder and I don't know how to set url so that the presenters are called. Please help, thanks.

Machy8
Member | 59
+
0
-

If you want to pass handle method url into the ajax in the linked file, you can set the url into a variable and then pass it into the ajax request something like

<script type="text/javascript">
	window.handleOptionSelectedUrl = {link optionSelected!}
</script>

// Some other script (using jQuery => dont know how it is in Angular)
<script type="text/javascript">
$('body').on("change", "select", function () {
		var val = $(this).val();

		$.ajax({
			'url': handleOptionSelectedUrl,
			'data': {optionVal: val}
		});

		return false;
	});

</script>

In your presenter

...

public function handleOptionSelected ($optionVal)
{
 ...
}

Last edited by Machy8 (2016-06-28 11:18)