我有一个web服务,并在其中有两种方法(select,insertdata)。我想用jquery在sql中插入一条记录。我怎样才能做到这一点?我已经制作了该代码,但它不起作用。请帮助我。我如何添加项目在sql中使用jQuery(ajax)通过web服务

我的web服务

Sqlconeection dd = new Sqlconeection();

int rowsInserted = 0;

[WebMethod]

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]

public string insertRecord(Int64 mbn,string name,double amt,bool Notify)

{

SqlConnection connection = dd.getconnection();

SqlCommand cmd = new SqlCommand("InsertData");

cmd.Connection = connection;

if (connection.State == ConnectionState.Closed)

connection.Open();

// string inser = "insert into expensive(mobileNumber,Name,Amount,Notify)values('" + mbn + "','" + name + "','" + amt + "','" + Notify + "')";

//cmd.CommandText = inser;

cmd.Parameters.AddWithValue("@mobile", mbn);

cmd.Parameters.AddWithValue("@Name", name);

cmd.Parameters.AddWithValue("@Amount", amt);

cmd.Parameters.AddWithValue("@Notify", Notify);

cmd.CommandType = CommandType.StoredProcedure;

rowsInserted= cmd.ExecuteNonQuery();

return string.Format("Thank you, {0} number of rows inserted!", rowsInserted);

}

[WebMethod(Description = "Returns all Products")]

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]

public DataTable selectdata(Int64 mnb)

{

DataTable dt = new DataTable();

SqlConnection conn = dd.getconnection();

SqlCommand cmd = new SqlCommand();

cmd.Connection = conn;

if (conn.State == ConnectionState.Closed)

conn.Open();

string select = "select mobileNumber,Name,Amount,Notify from expensive where mobileNumber='" + mnb + "'";

cmd.CommandText = select;

SqlDataReader dr = cmd.ExecuteReader();

dt.TableName = "expensive";

dt.Load(dr);

return dt;

}

我API代码

$(function() {

$('#btnSubmit').click(function() {

var mob = $('#txtmo').val();

var Nm = $('#txtName').val();

var amout = $('#txtAmt').val();

var notify = $('#txtnoty').val();

$.ajax({

type: "POST",

url: "InsertData.asmx/insertRecord",

data: "{ mob: '" + mob + "', Nm: '" + Nm + "',amount:'" + amout + "',notify:'" + notify + "'}",

contentType: "application/json; charset=utf-8",

dataType: "jsonp",

success: function (data) {

var obj = data.d;

if (obj == 'true') {

$('#txtmo').val('');

$('#txtName').val('');

$('#txtAmt').val('');

$('#txtnoty').val('');

$('#lblData').html(JSON.stringify(data.d));

}

},

error: function (r) {

console.log(r);

},

});

});

});

2015-10-15

Raj Gola

+0

请提供一些更多的细节,并显示为代码剪断,而不是整个程序。 –

+0

您的数据对象属性名称与您webmethod的启动项不匹配。 –

+0

同样在您的成功中,您检查webmethod是否返回'true',但它实际上会返回成功消息。 –

ajax在项目中怎么使用,我如何添加项目在sql中使用jQuery(ajax)通过web服务相关推荐

  1. 登录页面添加回车和单击登录事件 jQuery.ajax中的 beforeSend:function () 回调函数【日常记录】

    比较有意思的地方1: 实现如下功能可以两种方法 用jQuery.ajax中的 beforeSend:function () 回调函数:如下(下方有全部代码案例) beforeSend:function ...

  2. 织梦ajax表单提交参数错误,【织梦二次开发】织梦jquery+ajax方式提交自定义表单...

    我们在dedecms教程中学到很多,比如可以借助jquery ajax提交dedecms自定义表单到后台.此例只做为参考,实际项目中根据自己的情况酌情修改. html部分: 姓名: 电话: 留言: j ...

  3. ajax then fail done,我应该使用.done()和.fail()来获取新的jQuery AJAX代码而不是成功和错误...

    我这样编码: $.ajax({ cache: false, url:"/Admin/Contents/GetData", data: { accountID: AccountID ...

  4. oracle中删除一天记录吗,删除oracle SQL中超过24小时的记录(delete records older than 24 hours in oracle SQL)...

    删除oracle SQL中超过24小时的记录(delete records older than 24 hours in oracle SQL) 我想删除所有超过24小时的记录. 我使用以下查询相同, ...

  5. ajax获取后生成元素,获取动态的子元素生成的内容与jQuery AJAX

    这是一个Ajax的内容,我在页面上几个.因此,我想要做的是显示第1章容器可见 页面上,如果我这样做: var first_div = $('div[id^=chapters-container-]:f ...

  6. 在mysql表中如何变换列和行_在SQL中转换列和行的简单方法?

    有几种方法可以转换这些数据.在你最初的帖子中,你说PIVOT对于这个场景来说似乎太复杂了,但是可以很容易地使用UNPIVOT和PIVOTSQL Server中的函数. 但是,如果您无法访问这些函数,则 ...

  7. ruby三元操作符_在Ruby中使用操作符将元素添加到数组实例中

    ruby三元操作符 In the previous articles, we have gone through ways through which we can create Array inst ...

  8. ORACLE EBS中消息队列fnd_msg_pub、fnd_message在PL/SQL中的应用

    EBS 中集成的FND_MSG处理很方便的在form中很方便的弹窗.提示消息之外,在写PL/SQL包的时候,也可以方便的进行借用来进行错误信息的收集.并且这个是基于session的,不同于客户化的lo ...

  9. Google Earth Engine(GEE)——将影像中的云层显示出来并添加到影像波段中(Landsat8 oil)

    之前我们只知道要去除影像中的云和阴影,但是我们并不清楚如何查看详细的云和阴影,此次,我们就通过加载影像的云和阴影来查看具体的效果,这里我们所建立的函数有点像去云的函数一样. 代码: // 对Lands ...

最新文章

  1. 将ArXiv中的Reference导入EndNote
  2. datetime-时间日期模块
  3. 案例:实现商品分类导航栏
  4. quartus仿真25:JK触发器构成的模7计数器(分析)
  5. SpringBoot之lombok引入后@Data无法生成getset方法
  6. 探讨 “tun2socks” 技术的一些问题
  7. 基于simhash的文本去重原理
  8. 一个大学生的人生随笔
  9. 实验方法怎么写_作文《你真好》怎么写?语文课本里找方法,附审题、写作思路...
  10. cocos2dx 精灵触摸
  11. 【科普】一读就懂:CPU到底是怎么识别代码的?
  12. 7月编程排行榜新鲜出炉,再次上演神仙打架!
  13. python之图片文本识别
  14. 游戏UI程序设计与开发
  15. 一分钟带你了解新版系统集成资质——信息系统建设和服务能力评估(CS)
  16. 怎么找属于自己最优的2B增长模型?
  17. 解决addClass不起作用的小妙招
  18. 计算机辅助药物设计在药物合成中的应用,计算机辅助药物设计在药物合成中的应用_郑彦.pdf...
  19. AWG含义及尺寸电流对照表
  20. 市场调研-全球与中国云文档管理软件市场现状及未来发展趋势

热门文章

  1. Java 集合类(一)
  2. 图片(img标签)的onerror事件,你有用过嘛?
  3. html5实现获取地理位置信息并定位
  4. Java练习:用IF()进行数字排序
  5. ORA-01578和ORA-26040--NOLOGGING操作引起的坏块-错误解释和解决方案(文档ID 1623284.1)...
  6. 《Spring 5 官方文档》26. JMS(二)
  7. Java必会的面试题
  8. PowerShell 6.2 PSCommandNotFoundSuggestion
  9. 为 MySQL/MariaDB 开启 Binlog 功能
  10. 快速傅里叶变换(FFT)算法【详解】