How to call action of Controller outside the controller in Zend Framework? - zend-framework

I am using Xajax in Zend Framework. I need to call action of particular controller in function of Xajax Class I have created.

Can you not place the action code you need to call into the model and then call it from there within the action and wherever else like:
$model = new Model;
$model->methodToCall();

Use jQuery. It makes AJAX easy.
$.ajax({
url: '/my-controller/my-action',
success: function(data) {
alert('Successful response');
}
});
In Zend Framework, create a controller action that you want to call using AJAX and send a response body that you want to use (either XML, JSON, or HTML for example).

Related

How to do an AJAX post to an Umbraco Web Api

I am using Umbraco 8.17 and I am trying to do an ajax post to an umbraco web api. I know from the Umbraco documentation that I need to make a new controller that extends UmbracoApiController. I also know that when I want to call a method in this controller I need to put "/Umbraco/Api/" at the head of the url. So if my controller is in the base folder of controllers and my controller is named myController and the method I want to call on that controller is MyMethod, the url would be something like "https://localhost:44305/Umbraco/Api/myController/MyMethod" if I were to be running the code from debug in Visual Studio.
Now from a partial view I want to trigger a javascript function that does a AJAX call to that method "assume the method takes no parameters:. My AJAX call in my partial view (cshtml) file would look like this.
function MYAJAXCAll() {
alert("In the function call");
$.ajax(
{
type: "POST",
url: "/Umbraco/Api/myController /MyMethod",
success: function (response) {
alert(response);
}
});
}
Note that at this point I am just trying to get the method call to work. once I have that done I can go back and make it actually do something meaningful.
The problem is that the ajax call is not working. It doesn't even seam to be firing. I will get the alert but nothing else. note that I do have a breakpoint in the method that should be catching if the method is called and that is not happening.
Ok I got the simple web api call to work using jQuery.
Here is the code that I used to make it work:
$(document).ready(function() {
$.getJSON("/Umbraco/Api/myController/MyMethod")
.done(function (data) {
alert(data);
});
});

How can I detect clicks on a JavaFX WebView from the main application?

Currently I do this by adding a Javascript event handler to the HTML content which sets a global variable according to the clicked item:
<script>
var clicked="";
</script>
<span onmousedown="clicked='me';">me</span>
then from the main application I query the content of this variable in the webview's mouse clicked handler:
webview.setOnMouseClicked(new EventHandler[MouseEvent]{
def handle(mouseEvent:MouseEvent){
if(mouseEvent.getEventType().toString()=="MOUSE_CLICKED"){
val clicked=webview.executeScript("clicked").toString()
}}})
This happens to work but it feels like a hack. Is there a legitimate way by which the webview can request the application to refresh its content based on the element that was clicked?
As I do not know Scala, I can only provide you with an approach in Java, but you can probably figure out, how to transform it to Scala.
Register a bridge between the Java (or in your case Scala) code and JavaScript. The basics are described in this article by Oracle. The JavaScript in your page can make a call to the application, notifying it that a certain button was clicked:
public class MyBridge {
public void callbackFromJavaScript(String what) {
...
}
}
JSObject jsobj = (JSObject) webEngine.executeScript("window");
jsobj.setMember("java", new MyBridge());
Then you can make the call when an element is clicked and callbackFromJavaScript will be executed:
<span onmousedown="java.callbackFromJavaScript('me');">me</span>
From your callbackFromJavaScript you can then easily call a JavaScript function and pass along an object (e.g. JSON) and the JS function will update the page, or you can load a completely different content.

Typo3 Neos Cannot Load Custom Plugin JS On Backend, Must Refresh To Make It Works

i'm trying to load my custom plugin on backend, e.g. datatables.js. But the JS is not working, i must refreshing the page once to make it works, there is also no error on the backend webbrowser console. How to solve this?
Any help would be much appreciated! thanks.
I don't think you should use document ready as this event is only fired once in the backend (unless you refresh the entire be). Instead you should use Neos.PageLoaded.
if (typeof document.addEventListener === 'function') {
document.addEventListener('Neos.PageLoaded', function(event) {
// Do stuff
}, false);
}
You can find documentation here:
http://docs.typo3.org/neos/TYPO3NeosDocumentation/IntegratorGuide/InteractionWithTheNeosBackend.html
May be your database.js is loaded before the dom a totaly loaded.
So i suggest to add a event onload to your body to load the Constructor or init function.
//jquery
$(document).ready(function(){
//INIT CONSTRUCTOR FUNCTION
});
//JS
document.body.onload = function(){
//INIT CONSTRUCTOR FUNCTION
};

display confirmation message on submit in zend php

Hi I have created a zend_form_element_submit. Now i want to display a confirmation message when someone clicks on submit. And when the user selects yes or ok, the form should be submitted. I read about javascript confirm() function, but was wondering if there is anything provided by zend.
You can do it using Zend Framework but in my opinion, I think it's more user-friendly to use javascript to handle this kind of thing.
For example, you would trigger a jQuery Dialog (modal confirmation) once the user click on the submit button. More information about jQuery Dialog here.
To do that, you should assign an identifier to your Zend_Form subclass and assign a javascript submit handler to that form.
To assign an id to the form, use the setAttrib() function in your Zend_Form::init() function:
/**
* init the form
*/
public function init()
{
$this->setAttrib('id', 'search-form');
.....
}
and then you can use this event handling code to override the form's submit function:
// submit search form
$('form#search-form').submit(function() {
if (confirm("....")) {
return true;
}
return false;
});
The FlashMessenger component is what you need in this case. You can choose to render the messages via direct HTML or via JavaScript.
FlashMessenger Action Helper
FYI: you can build a partial view template which only gets rendered if there are >0 messages.
On the button you can set an attribute:
$button->setAttribute('onclick', 'if (confirm("Are you sure?")) { document.form.submit(); } return false;');

How to call user defined jquery or ajax function calls in Jqtouch

I am trying to add some functionality in a wordpress theme based on JQtouch. I want to run an ajax call to replace the content of a div. But the jQtouch not allowing me to run the code. It runs its default event.
i Have used this code to bind the function, where listArticles() will call my Ajax request.
$(function(){
$('a[href="#articles"]').bind('click', listArticles());
});
Your callback is wrong, it should either point to the function or be an anonymous function itself.
$(function(){
$('a[href="#articles"]').bind('click', listArticles);
});
or
$(function(){
$('a[href="#articles"]').bind('click', function() { listArticles() });
});