Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vipin93's avatar
Level 13

How can I convert jquery to axios?

here is I try to convert this jquery ajax call jqery to axios but could not getting clue here is my code

chrome.runtime.onInstalled.addListener(function() {
  var body = "selection";
  var name = "jhone doe";
  var all_col = chrome.contextMenus.create({"name": name, "contexts":[body],"id": "context_selection"});  
});

var open_window_ids=[]

function getSummary(body_resp) {

    var body_data;

    $.ajax({
        url: 'http://mereac.dev/',
        type: 'POST',
        data: JSON.stringify(body_resp),
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        async: false,
        success: function(data) {
            body_data = data;
        }
    });

    return body_data;
}
0 likes
3 replies
topvillas's avatar

You could try reading the docs.

axios.post('http://mereac.dev/')
.then(response => body_data = response.data))
.catch(error => console.log(error));
mccubbin's avatar

@topvillas He is trying to replicate "async: false". Your answer does not duplicate that functionality.

martinbean's avatar

@mccubbin This thread was 4 years old. Did you really need to dig it up just to post that? I think the OP would have found out by now whether the suggestion was valid or not…

2 likes

Please or to participate in this conversation.