jQueryeach()结果数组到php到数据库
基本上我正在做的是制作一种邀请系统,用户单击用户,他们进入一个列表,一切正常,我可以使用each()获取他们的id,但我需要通过jQuery Ajax将其传递到php 将其发送到数据库以获取通知。这基本上就是我所拥有的:
$(".group-video-create").click(function(){
var url = $(".group-input-url").val();
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
var checked_url = url.match(exp,"<a href='$1'>$1</a>");
if(checked_url)
{
$("#group-input-names li").each(function(){ // This is the relevant code
var user_id = $(this).attr("id"); // Here too
}); // & here
if(user_id)
{
$.ajax({
type: "POST",
//url: "",
//data: "", //this would be an array of all of the ids, (could be 1, could be 100).
cache: false,
success: function(html){
///Once all invitations have been sent to the database it would then load a new div and hide the previous one.
}
});
}
}
});
如果您想了解我想要完成的任务,请转到这里:
http: //www.kithell.com/#/video
usr: [电子邮件受保护] 通过:phpfreaklogin
在群组视频下。 (登录后您应该会自动定向到那里)
Basically what I am doing is making a sort of invitation system, the user clicks on users and they go into a list, that all works, I can get the ids of them using each() but I need to pass it through jQuery Ajax to php to send it to the database for notifications. This is basically what I have:
$(".group-video-create").click(function(){
var url = $(".group-input-url").val();
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
var checked_url = url.match(exp,"<a href='$1'>$1</a>");
if(checked_url)
{
$("#group-input-names li").each(function(){ // This is the relevant code
var user_id = $(this).attr("id"); // Here too
}); // & here
if(user_id)
{
$.ajax({
type: "POST",
//url: "",
//data: "", //this would be an array of all of the ids, (could be 1, could be 100).
cache: false,
success: function(html){
///Once all invitations have been sent to the database it would then load a new div and hide the previous one.
}
});
}
}
});
if you want to see what I'm trying to accomplish just go here:
http://www.kithell.com/#/video
usr: [email protected]
pass: phpfreaklogin
It's under Group Video. (You should be automatically directed there once logged in)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您也许可以使用 jQuery.serialize 来捆绑所有表单数据。另外, jQuery.post 是使用 jQuery 执行 POST 请求的一个不错的快捷方式。 ajax。
一个粗略的例子可能是这样的:
You might be able to use jQuery.serialize to bundle up all of your form data. Also, jQuery.post is a nice shortcut for doing a POST request with
jQuery.ajax
.A rough example might look this:
这是一种可能性
http://jsfiddle.net/nickywaites/9GZ2e/
Here is one possibility
http://jsfiddle.net/nickywaites/9GZ2e/