0

I have ajax request,

        onLanguageSelection: function () {
            $("#submitLocalizationVm")
                .click(function (event) {
                    var localizationId = $("#surveySectionsLocalizationList option:selected").val();
                    var surveySectionId = $("#SurveySectionId").val();
                    if (localizationId) {
                        LinkAjax.ajaxRequest($localizationEditVmUrl += surveySectionId + "&localizationId=" + localizationId,
                        "random data",
                        "localizationPartial",
                        null,
                        null,
                        localizationSelectList.populateLocalizationViewModel);
                    }
                });
        },

I have an mvc controller with the following method.

   public string GetEditLocalizationInformation(Guid surveySectionID, Guid localizationId)
        {
            //...
            return new JavaScriptSerializer().Serialize(model);
        }

I am getting an error. The first time I make a request with the parmaeters surveySectinID = 2 and localizationId = 3 it is successful. If I make another request without refreshing the page with the parmeters surveySectinID = 2 and localizationId = 4 then localizationId will concatenate both values from the request and become 34. What is going on here? The ajax request is sending the correct values through.

5
  • Are yous sure that the ajax is sending correct data? how did you confirm that? Commented May 23, 2016 at 11:00
  • With the dev tools. I can see the localizationId value being sent is only 3 on the first request and 4 on the second. Commented May 23, 2016 at 11:02
  • And in controller you get the value as the concatenated one? What is the value of Request.QueryString there? Commented May 23, 2016 at 11:05
  • Moment, I will tell you soon. Commented May 23, 2016 at 11:09
  • 1
    aahhh your correct!! I was using += to concatenate the string so on the second request it messed up!! Thanks for that. Commented May 23, 2016 at 11:21

1 Answer 1

1
LinkAjax.ajaxRequest($localizationEditVmUrl += surveySectionId + "&localizationId=" + localizationId,

You have issue with above line. The $localizationEditVmUrl variable seems to be global and because you are concatenating the parameters the next AJAX requests will have the additional parameters. Change it like this and it should be fine

LinkAjax.ajaxRequest($localizationEditVmUrl + surveySectionId + "&localizationId=" + localizationId,
Sign up to request clarification or add additional context in comments.

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.