gpt4 book ai didi

javascript - 无法获取未定义空引用的属性 'pingInterval'

转载 作者:行者123 更新时间:2023-11-28 06:25:05 26 4
gpt4 key购买 nike

我提交了一个表单以从数据库中获取对象。

我需要在 json 字符串中添加 varbinary(MAX) 类型(图像)列,并通过 WebMethod 将其发送到 Ajax 以显示在页面中,以及对象的其余属性。所以在类中它的string类型而不是byte[]类型。

在编码部分我收到 Javascript 运行时错误:

Unable to get property 'pingInterval' of undefiened null reference.

 <form id="form1" runat="server">
Arrival:
<input type="text" id="txtArrival" />
departure:
<input type="text" id="txtDeparture" />
Nob:
<input type="text" id="txtNob" />
<input type="button" id="btnSubmit" value="Get Rooms" />
</form>

类别:

public int ID { get; set; }
public string RoomType { get; set; }
public string RoomNumber { get; set; }
public string RoomTitle { get; set; }
public decimal Price { get; set; }
public string ServiceName { get; set; }
public string Photo { get; set; }

Ajax :

$(document).ready(function () {
$(function () {
$("#btnSubmit").click(function () {
var arrival = $("#txtArrival").val();
var departure = $("#txtDeparture").val();
var nob = $("#txtNob").val();

$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebForm2.aspx/GetRooms",
data: "{'arrival':'" + arrival + "','departure':'" + departure + "','nob':'" + nob + "'}",
dataType: "json",
success: function (data) {
alert(data.d);

},
error: function (result) {
alert("Error!");
}
});
});
});
});

Web方法:

[WebMethod]
public static string GetRooms(string arrival, string departure, string nob)
{
string val = "";
DateTime d1 = Convert.ToDateTime(arrival);
DateTime d2 = Convert.ToDateTime(departure);
int noib=Convert.ToInt32(nob);
var jSerialize = new JavaScriptSerializer();
List<Room> lst = new List<Room>();
using (SqlConnection con = new SqlConnection("Server=.;Database=ResDB;Trusted_Connection=True;"))
{
using (SqlCommand cmd = new SqlCommand("roomsAvailable", con))
{
cmd.Parameters.AddWithValue("@arr", d1);
cmd.Parameters.AddWithValue("@dep", d2);
cmd.Parameters.AddWithValue("@nob", noib);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader sr = cmd.ExecuteReader(); ;
while (sr.Read())
{
Room r = new Room();
r.ID = Convert.ToInt32(sr["ID"]);
//objects..
if (sr["Photo"] != System.DBNull.Value)
{
byte[] p = (byte[])sr["Photo"];
r.Photo = Convert.ToBase64String(p);// error here
}

lst.Add(r);
val = jSerialize.Serialize(lst);
}
con.Close();
}
}
return val;
}

WebMethod 中的此语句有错误:

 r.Photo = Convert.ToBase64String(p);

最佳答案

将 JQuery 托管文件更改为新版本后,

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>

错误消失了!

关于javascript - 无法获取未定义空引用的属性 'pingInterval',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35195626/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com