如何在 ajax 调用中使用 javascript 中的 GET 方法传递数据
How to Pass Data in ajax call using GET Method in javascript
我正在使用 qunit 在 javascript 中编写单元测试用例。我正在调用一个 URL 使用 ajax 调用并使用 GET 方法,但它没有调用 URL。我在下面提供测试:
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();
}
});
});
有人可以建议我在 ajax 通话中更改什么吗??
我试过了 this Whosebug answer but it is not working
提前致谢。
试试这个
$.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 并不意味着在 "data" 属性中格式化 JSON 字符串 ..
您仍然需要传入 "data" 属性的查询变量。在这种情况下,我使用 some_query_var。
我正在使用 qunit 在 javascript 中编写单元测试用例。我正在调用一个 URL 使用 ajax 调用并使用 GET 方法,但它没有调用 URL。我在下面提供测试:
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();
}
});
});
有人可以建议我在 ajax 通话中更改什么吗?? 我试过了 this Whosebug answer but it is not working 提前致谢。
试试这个
$.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 并不意味着在 "data" 属性中格式化 JSON 字符串 .. 您仍然需要传入 "data" 属性的查询变量。在这种情况下,我使用 some_query_var。