0

I'm have a problem loading a site. Using this code:

$.ajax({
        type: "POST",
        //url: '@Url.Action("/TellFriendPopup")',
        url: '/Property/TellFriendPopup',

        data: { "SenderName": SenderName, "senderMail": senderMail, "receiverMail": receiverMail, "comments": comments, "urlLink": urlLink, "subjectId": subjectId },
    success: function (data) {
        $("#result").html("<ul><li>Name: " + data.nameret + "</li><li>Email: " + data.emailret + "</li><li>Message: " + data.messageret + "</li></ul>");

        $(".dialog").dialog("close");
    },

The problem is that I had to move the code to a JavaScript file, instead of the MVC4 View, where i could use the @Url.Action method. But it is not working in JavaScript. It Just gives me this error POST http://localhost:54717/Property/ContactPopup 404 (Not Found). The reason as I can see is that it's the Globalization that it's missing. Because the url should look like this http://localhost:54717/da/Property/ContactPopup or http://localhost:54717/en/Property/ContactPopup

2
  • Why can you add /da/Property/ContactPopup in ajax call Commented Jan 15, 2013 at 10:34
  • Because if the language is english. the string is /en/Property/ContactPopup instead. Commented Jan 15, 2013 at 10:36

3 Answers 3

2

You could get the first folder of the pathname. As long as that is where the language code is on every page.

var language = location.pathname.split("/")[1];

url: language + '/Property/TellFriendPopup'
Sign up to request clarification or add additional context in comments.

Comments

2

You can have language in hidden field.

var language = document.getElementById('language`).value;

url: '/' + language + '/Property/TellFriendPopup'

Comments

1

Can you try changing this: url: '/Property/TellFriendPopup',

to this url: '../Property/TellFriendPopup',

Comments

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.