user1858851
user1858851

Reputation: 147

Correct URL in ajax call JavaScript

I have a GET ajax call as follows :

var changeUrl = "changePriority?newValue=" + targetValue + "&justification=" + justification
if (dataInfo == "row") {
    changeUrl += "&id=" + id
}
changeUrl += "&executedConfigId=" + executedConfigId + "&currUser=" + currentUser + "&productName=" + productName + "&eventName=" + eventName + "&alertDetails=" + JSON.stringify(alertArray);
//if the selected signal is not null then we show the product names

$.ajax({
    url: changeUrl,
    type: "GET",
    success: function (data) {
        for (var index = 0; index < checkedRowList.length; index++) {
            var row = checkedRowList[index]
            signal.list_utils.change_priority(row, targetValue);
        }
        $('#change-priority-modal').modal('hide');
        if (applicationName == "Signal Management") {
            signal.list_utils.set_value(parent_row, 'dueIn', id, signal.list_utils.get_due_in, applicationName);
            $(parentField).html(targetValue);
        }
        location.reload();
    },
    error: function (exception) {
        console.log(exception);
    }
});

The value of changeUrl as I get in my browser's developer console is :

http://localhost:8080/signal/singleCaseAlert/changePriority?newValue=Medium&justification=test%20justification%20first.&id=6816&executedConfigId=6704&currUser=15&productName=Wonder%20Product&eventName=1.Pyrexia&alertDetails=[{%22alertId%22:%226816%22,%22event%22:%221.Pyrexia%22,%22currentUser%22:%2215%22}]

But I get a 400 bad request status and a http header parse error in the backend. Can someone help me resolve this?

Upvotes: 0

Views: 91

Answers (1)

Pandelis
Pandelis

Reputation: 1968

On your JSON.stringify(alertArray) you'll need to also encodeURI();

encodeURI(JSON.stringify(alertArray));

A better solution would be send your JSON in the body of a POST request if thats feasible within your design

Upvotes: 1

Related Questions