最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to Pass Data in ajax call using GET Method in javascript - Stack Overflow

programmeradmin3浏览0评论

I am writing Unit Test Case In javascript using qunit. i am calling one URL using ajax call and using GET method but it is not calling URL. I am Providing Test below:

 QUnit.test( "Importing Grid", function(assert) {
    var done = assert.async();    
    var data = {
        "info": {"view":"LATEST","mode": 1,"memberId": 1001,"baselineId": -1}
    }
    console.log(cuboid_id+" : "+cuboid_name);
    $.ajax({
        url: Globals.baseURL + "rest/grid/"+cuboid_id,
        type: "GET",
        dataType: "application/json",
        data: JSON.stringify(data),
        contentType: "application/json",
        success: function(result){                
            console.log(JSON.stringify(result));                                                       
            assert.equal(result !=null,true,"Response should not be null");               
            assert.equal(result[0].error,"Whitebaord ID NOT FOUND","InValid Whiteboard ID");               
            done();
        }
    });
});

Can someone suggest me what to change in ajax Call?? I tried this stackoverflow answer but it is not working Thanks In Advance.

I am writing Unit Test Case In javascript using qunit. i am calling one URL using ajax call and using GET method but it is not calling URL. I am Providing Test below:

 QUnit.test( "Importing Grid", function(assert) {
    var done = assert.async();    
    var data = {
        "info": {"view":"LATEST","mode": 1,"memberId": 1001,"baselineId": -1}
    }
    console.log(cuboid_id+" : "+cuboid_name);
    $.ajax({
        url: Globals.baseURL + "rest/grid/"+cuboid_id,
        type: "GET",
        dataType: "application/json",
        data: JSON.stringify(data),
        contentType: "application/json",
        success: function(result){                
            console.log(JSON.stringify(result));                                                       
            assert.equal(result !=null,true,"Response should not be null");               
            assert.equal(result[0].error,"Whitebaord ID NOT FOUND","InValid Whiteboard ID");               
            done();
        }
    });
});

Can someone suggest me what to change in ajax Call?? I tried this stackoverflow answer but it is not working Thanks In Advance.

Share Improve this question edited Nov 18, 2019 at 11:39 Mosè Raguzzini 15.9k1 gold badge34 silver badges46 bronze badges asked May 28, 2018 at 12:13 Jaydeep BobadeJaydeep Bobade 1,0353 gold badges17 silver badges26 bronze badges 6
  • 2 Possible duplicate of How to pass parameters in GET requests with jQuery – Hamza Abdaoui Commented May 28, 2018 at 12:15
  • i tried that but it is not working – Jaydeep Bobade Commented May 28, 2018 at 12:16
  • @HamzaAbdaoui here he is not passing parameters as key value pair but instead JSON object. – Pavan Divekar Commented May 28, 2018 at 12:19
  • 1 try removing dataType and data fields from ajax. if you want to send data in get, append those fields in url, or use post. – Ronn Wilder Commented May 28, 2018 at 12:21
  • 1 Request with GET/HEAD method cannot have body. This will create TypeError as it will fail to execute fetch on window. You should use query param in the url to send data. – Pavan Divekar Commented May 29, 2018 at 9:44
 |  Show 1 more ment

1 Answer 1

Reset to default 2

try this

$.ajax({
    url: Globals.baseURL + "rest/grid/"+cuboid_id,
    type: "GET",
    dataType: "application/json",
    data: {some_query_var : JSON.stringify(data)},
    contentType: "application/json",
    success: function(result){
        console.log("***********************++++++++++++++*************************");
        console.log(JSON.stringify(result));                                                       
        //assert.equal(result !=null,true,"Response should not be null");               
        //assert.equal(result[0].error,"Whitebaord ID NOT FOUND","InValid Whiteboard ID");
        assert.equal(1,1); 
        done();
    }
});

"dataType json" in ajax jquery doesn't mean for formating JSON string in "data" attribute .. you still need the query variable passing in the "data" attribute. wich is in this is case i use some_query_var.

发布评论

评论列表(0)

  1. 暂无评论