0

[I realise this might seem like a stupid question but I am lost.]

Using umbraco 4.9 I have a multi-lingual site where I have made an event handler to replicate content nodes to all languages as they are created in the back office to all languages. I am now trying to attach this to a custom context menu item(umbraco.interfaces.IAction) to give the creator a choice.

In the context menu item it is only possible to call a javascript function as a string. I shouldn't touch the umbraco code itself so how can I pass a value to a web service? Where do I include the reference?

This is what I have at the moment:

public string JsSource
{
     get 
     { 
         return "function AddItem(){" +
                 "var multiLang = confirm('Create for all languages?');" +
                  //"$.ajax({" +
                  //"type: 'Post'," +
                  //"url: 'TryAgain.aspx/' + SendMultiVal" +
                  //"data: multiLang})" +
                  //"PageMethods.SendMulti(multiLang);}" +
                  string.Format("{0}.actionNew()", ClientTools.Scripts.GetAppActions)+"};"; 
     }
}

Thanks in advance.

7
  • Typically this is done using a technique called AJAX -- have you looked under that terminology? Commented Nov 14, 2012 at 15:27
  • @Hogan yes I have. I can't seem to find how to make the reference. The javascript function is returned as a string so I am not writing it directly to the pages script files. Commented Nov 14, 2012 at 15:29
  • AJAX does not work by writing to the pages script file. Please read about AJAX and do some examples or post some code you think should work but does not. Right now your question sounds like "do it for me" which won't go far on this site -- ppl are prone to ignore those type of questions. Commented Nov 14, 2012 at 15:33
  • @Hogan I understand how ajax works(at least I think I do) but I still can't see how to call a web service nor which type of. I added the function call above. Commented Nov 14, 2012 at 15:37
  • I really wouldn't have asked here if I could have found it anywhere else. Commented Nov 14, 2012 at 15:41

1 Answer 1

1

So the first thing that you need to do is to store the boolean value in a variable called boolvalue and then call the callservice function once you have the value.For eg:

  CallService("POST", "YourServiceUrl",boolvalue,
        function (data) {
            alert("Service Call Success");
        },
        function (result) {
            alert('Service call failed: ' + result.status + '' + result.statusText);
        });   

This will make a service call and get data from service if it returns some data.

   CallService = function (method, serviceUrl, value, successHandler, errorHandler) {
    $.ajax({
        type: method,
        url: serviceUrl,
        contentType: "application/text; charset=utf-8",
        dataType: "json",
        data:JSON.stringify(value),
        success: successHandler,
        error: errorHandler
    });
};

Modify the dataType and dataType fields depending upon the type of data that you send and receive from the service. Look into this if you need more information: http://api.jquery.com/jQuery.ajax/

Let me know if this works out for you.

Sign up to request clarification or add additional context in comments.

8 Comments

I am trying to get it to work but umbraco is doing my head in. If I get it going I'll get back to you. Thanks!
This example is using jQuery -- not specified in the question.
Function won't call when I introduce Ajax. (Without it I can call a simple confirm or alert)
@The_Cthulhu_Kid - are you including the jQuery javascript library?
@Hogan It is included on all the umbraco pages but since I am injecting the function as a string I'm not sure if it gets it and I can't include the reference in the function can I?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.