Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Cornel 6 posts 26 karma points
    Oct 07, 2011 @ 17:23
    Cornel
    0

    On Click jQuery post to razor file

    Hi guys,

    This is my first post :)

    The issue is I have is I'm able to post using a jQuery event to a .cshtml if I'm not using umbraco.

     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"></script>
          <p id="load">load</p>
        <script type="text/javascript">
            $("#load").click(function () {
                $.post("/Scripts/FileUpload3", { name: "John", time: "2pm" },
                   function (data) {
                       alert("Data Loaded: " + data);
                   });
            });
        </script>

    The .cshtml file is submitting some info to a database and the project workes very well.

    Any ideas why this will not work in a umbraco enviroment?

    Thank you

    Cornel

  • Rodion Novoselov 694 posts 859 karma points
    Oct 07, 2011 @ 17:32
    Rodion Novoselov
    0

    Hi. What is '/Scripts/FileUpload3' ? From the code it looks that it's supposed to be sort of a web service. Is it really accesible by this url? 

  • Cornel 6 posts 26 karma points
    Oct 07, 2011 @ 17:40
    Cornel
    0

    Hi Rodion,

    Thank you for your reply.

    /Scripts/FileUpload3.cshtml

    Strangly but is working without the extension.

    I've tryed it with and without the extension in umbraco but still nothing.

    Thank you

    Cornel

  • andrew 13 posts 36 karma points
    Oct 07, 2011 @ 21:06
    andrew
    0

    Hi Cornel--

    If I recall correctly, you need to explicitly expose the methods in the assembly to be able to use AJAX calls in the /config/restExtensions.config file.  More information on it can be found at http://our.umbraco.org/wiki/reference/umbraco-base/simple-base-samples/the-restextensionsconfig-file

    Hope this is what you're looking for-
    -Andrew

  • Evan Jardine 108 posts 168 karma points
    Oct 10, 2011 @ 01:09
    Evan Jardine
    0

    Hi Cornel

    Have a look at Sebastiaan blog post on Razor vs "/base" to output JSON in Umbraco, http://cultiv.nl/blog/2011/7/25/razor-vs-base-to-output-json-in-umbraco/

    Basically you have the two options write a class using umbraco base or follow the example in the blod post to use Razor.

    If you have an Umbraco Tv subscription I'd also reccomend having a look at these two videos on base;

    http://umbraco.com/help-and-support/video-tutorials/developing-with-umbraco/base-and-ajax-development/introduction-to-base.aspx

    http://umbraco.com/help-and-support/video-tutorials/developing-with-umbraco/base-and-ajax-development/creating-an-ajax-form.aspx


    @andrew - you can now attribute you base classes and methods to expose them instead of editing the restExtensions.config.

    using umbraco.presentation.umbracobase;

     

    [RestExtension("myAlias")]
    class myBaseClass.....

    [RestExtensionMethod(returnXml= false)]
    public static string Save(string reportId)....

    Cheers

    Evan


     

  • Rodion Novoselov 694 posts 859 karma points
    Oct 10, 2011 @ 01:22
    Rodion Novoselov
    0

    Hi, Cornel. I also tried to use a .cshtml page inside Umbraco and found that there're also other things that should be taken into consideration.

    I googled the link below and think that it can be very usefull to read:

    http://joeriks.wordpress.com/2011/03/03/an-ordinary-webmatrix-app-in-an-umbraco-subfolder/

  • Cornel 6 posts 26 karma points
    Oct 10, 2011 @ 10:06
    Cornel
    0

    @Rodion, 

    The thing that I want to do is not just loading a cshtml. I want ot post on a jQuery event some data to a cshtml.

    The jQuery event is very important because I want to do it without a refresh.

     

    Thank you

    Cornel

  • Cornel 6 posts 26 karma points
    Oct 10, 2011 @ 10:09
    Cornel
    0

    @Evan,

    I think that the video create an ajax form should solve my problem.

    Because one the topics is submitting your form using a jQuery event.

     I'll watch it later today and let you know.

    Thank you

    Cornel

  • Cornel 6 posts 26 karma points
    Oct 10, 2011 @ 10:14
    Cornel
    0

    @Andrew

    Maybe this sounds crazy, but I'm pretty new to this stuff.

    How do I "explicitly expose the methods in the assembly to be able to use AJAX calls in the /config/restExtensions.config file" :)

     

    Thank you

    Cornel

  • Rodion Novoselov 694 posts 859 karma points
    Oct 10, 2011 @ 10:15
    Rodion Novoselov
    0

    Yeh, I understand that. However, calling it with jQuery technically doesn't differ from usual http post/get methods, so you can use for instance the console/network panels of FireBug to trace it. Can you do it and tell if there're any errors?

  • jaygreasley 416 posts 403 karma points
    Oct 10, 2011 @ 12:03
    jaygreasley
    0

    Have you added the Scripts folder in umbracoReservedPaths in web.config ? If not, Umbraco will hijack the web service I think

    hth

    Jay

  • Cornel 6 posts 26 karma points
    Oct 10, 2011 @ 13:30
    Cornel
    0

    @Jay

    It is now but still nothing :)

     <add key="umbracoReservedPaths" value="~/umbraco,~/install/,~/scripts/" />
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies