Question

I have a function which currently passes an account code (derived from a combo box) to the server. Currently it does this by sending the request in the body - I need it to send as a URL parameter. So for example the URL should be:

localhost:1234/myProject/WebApp/Data?accountCode=Full

Assuming full is selected.

My code below works as a request body but my attempts to amend it to submit as a URL request have failed.

 accountSelected: function () {
                var saccountCode = $("select#accountcombo").val();
                var stringAccountCode = saccountCode.toString()
                console.log("Account is: " + stringAccountCode);
                var myURL = "WebApp/Data";
                $.ajax({
                    url: myURL,
                    type: "POST",
                    data: {
                        "accountCode": stringAccountCode
                    },
                    dataType: "text",
                })

I have been looking at using $.param but couldn't get anything to work and also read on other questions about using $.get but when I change my code above to a "GET" i get an error "Request method 'GET' not supported" - the server is expecting a POST request. Any way i could achieve this?

Thanks

Was it helpful?

Solution

Try,

URL: "localhost:1234/myProject/WebApp/Data?accountCode="+stringAccountCode

Appending number of parameters you want example

?accountCode="+stringAccountCode+"&aa="+someAccount
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top