ajax请求是更大功能的一部分。我试图避免用代码堵塞页面,所以这里是请求本身:
$.ajax({
url: "PubMedNewSnp.aspx/GetEdits",
data: "{ 'Drug':'" + drug + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (alreadyInDB) {
var TableName = "combo";
var curRow = curComboRow;
if (alreadyInDB) {
TableName = "edit";
curRow = curEditRow;
curEditRow++;
}
else {
curComboRow++;
}
do stuff...
}
});
这是aspx.cs文件:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static bool GetEdits (string Drug) {
//masterDBDataContext masterDB = new masterDBDataContext();
bool alreadyInDB = false;
if (Drug == "bannana")
{
alreadyInDB = true;
}
//var inTbl = (from a in masterDB.tbl_custom_SNPs_Alls
// join
// where a.PubMedInfoId == Convert.ToInt32(curRow[0]) &&
// a.DrugId == Convert.ToInt32(curRow[0])
// select r).ToList();
return alreadyInDB;
}
由于某种原因没有回复。在网络选项卡中,我看到的是请求标头和请求有效负载。还有一个警告:显示临时标题。不确定那是什么意思。对不起,如果问题含糊不清,或者没有给出信息。我很乐意提供更多,只是不确定还需要什么。
提前致谢。
答案 0 :(得分:0)
这是你的inInDB的输出,它是json格式。
对象{d:true}或对象{d:false}
$.ajax({
url: "PubMedNewSnp.aspx/GetEdits",
data: "{ 'Drug':'" + drug + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (alreadyInDB) { // alreadyInDB is in json format. you need to access object property.
var TableName = "combo";
var curRow = curComboRow;
if (alreadyInDB.d) {
TableName = "edit";
curRow = curEditRow;
curEditRow++;
}
else {
curComboRow++;
}
}
});
希望有所帮助。