将jQuery与SQL Server数据库连接 [英] Connecting jQuery with the SQL Server Database

查看:426
本文介绍了将jQuery与SQL Server数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个jQuery功能,为此场景在下面给出.

考虑到用户单击网站上的图像,页面上会弹出一个jQuery对话框.对话框中有一个文本字段,用于输入图像的替代文本".当用户单击提交"按钮时,该页面上的文本应与图像的URL一起保存到我的中央网站的数据库中.

我已经能够使用以下代码 http: //pastebin.com/nxALvAPP

但是我想要帮助将图像文本"及其URL保存在数据库中.那怎么办?我不是专业人士.

感谢帮助!

解决方案

您必须将ajax请求以字段值作为数据拉到php页面.看看 http://api.jquery.com/jQuery.ajax/

到目前为止,我认为这不会给您带来任何问题.

//////////////////

基本上,您要做的是:

将点击事件添加到提交按钮:

$('#button_id').click(function(e) { 
  e.preventDefault();
  // button action
});

在此操作中,您将调用一个文件并添加数据,例如:

$.ajax({
  url: "savetext.asp",
  context: document.body,
  data: 'title='+$('#title').val(),
  success: function(){
    alert('ajax file called');
  }
});

这将向带有数据'title'的savetext.asp发送一个请求(该请求具有ID为title的输入字段的值).我不确定PHP的$ _REQUEST等效于什么,但是此参数(标题)是否在URL中发送到文件savetext.asp.

I am trying to build a jQuery functionality for which the scenario is given below.

Consider a user clicks on an image in the website, a jQuery dialogue box pops up on the page. The dialogue box has a text field to enter the 'alternative text' for the image. When the user clicks on the submit button, the text from this page should get saved into my central website's database along with the url of the image.

I have been able to get the jQuery dialogue box working (by going step and step in jQuery) with the following code http://pastebin.com/nxALvAPP

But I wanted the help to save the 'image text' and it's url in the database from. How can that be done? I am not really a pro.

Thanks for help!

解决方案

You'd have to pull an ajax request to a php page with the values of the fields as data. Take a look at http://api.jquery.com/jQuery.ajax/

As you've came so far, I don't believe this causes any problems for you.

///////////////////

Basically what you do is:

add an click-event to the submit button:

$('#button_id').click(function(e) { 
  e.preventDefault();
  // button action
});

within this action, you call up a file and add data, for example:

$.ajax({
  url: "savetext.asp",
  context: document.body,
  data: 'title='+$('#title').val(),
  success: function(){
    alert('ajax file called');
  }
});

This sends a request to savetext.asp with data 'title' (which has the value of the input field with the id title). I'm not sure what's the equivalent of PHP's $_REQUEST but this parameter (title) is send in the URL to the file savetext.asp.

这篇关于将jQuery与SQL Server数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆