cancel
Showing results for 
Search instead for 
Did you mean: 

I have a issue with Ajax and JQuery

viperboys
Star Contributor
Star Contributor

Hi.. 

I am working with Folder Rules. I want a POST method to be executed when a file is created in the folder. I upload the JS file to the SCRIPT directory. I have everything configured. This is the content of my file

function traer(){
var user = "Luis";
var name ="Diaz";
//alert("Nombre: " + user + " Apellido: " + name);

$.ajax({
type: "POST",
url: "http://localhost/alfresco/index.php/wp-json/gf/v2/workflow/webhooks/10/Fytn4QUNj9XWrzcvRzAPG79CB",
data:{Nombre:user, Apellido:name},
success: function(data)
{
alert ("Muy bien");
}
});


} // Cierra de la funcion TRAER
traer();

This works fine in my custom code but in Alfresco it doesn't work for me. 

This is my error

20 KB (Error: Failed to execute script 'workspace://SpacesStore/f2d8d60b-6bcd-425e-9b5c-6927b42d44f3': 04130025 ReferenceError: "jQuery" is not defined. (workspace://SpacesStore/f2d8d60b-6bcd-425e-9b5c-6927b42d44f3#6))
 

It does not detect the Jquery tag nor $ .Ajax

5 REPLIES 5

sanjaybandhaniya
Elite Collaborator
Elite Collaborator

Hi,

We can call ajax from client side javascript and javascript which you are using rule , it is server side script so you can not call ajax.

There is another way where you can call java method from script and from java code you can call external service.

Please refer below thread.

call-external-class-by-javascript-in-rules-of-folder 

Hi @sanjaybandhniya 

Do you have a practical example to practice a Post method?

Thank you

Hi,

Which type of example you want me to provide?

Hi @sanjaybandhniya 

Thank you very much for you helping

An example of how to execute a POST method on a folder rule. From the beginning I thought that this custom code would work for me

function traer(){
var user = "Luis";
var name ="Diaz";
alert("Nombre: " + user + " Apellido: " + name);

$.ajax({
type: "POST",
url: "http://localhost/alfresco/index.php/wp-json/gf/v2/workflow/webhooks/10/Fytn4QUNj9XWrzcvRzAPG79CB",
data:{Nombre:user, Apellido:name},
success: function(data)
{
alert ("Muy bien");
}
});


} // Cierra de la funcion TRAER
traer();

But the reality is that it is not as simple as it sounds. I would like an example of how to do a POST method step by step from a folder rule.

Thank you

Hi, Rulescript is server side script so you can not call ajax from that.