admin管理员组文章数量:1429688
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
1 Answer
Reset to default 2try 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.
本文标签: How to Pass Data in ajax call using GET Method in javascriptStack Overflow
版权声明:本文标题:How to Pass Data in ajax call using GET Method in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745439361a2658375.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论