【问题标题】:How to Build a jQuery array and move to the php, then use it on a PHP Function?如何构建一个 jQuery 数组并移动到 php,然后在 PHP 函数上使用它?
【发布时间】:2015-09-19 02:18:55
【问题描述】:
$(".divclass").each(function() {
    Build An Array with all .divclass ID ( 
});

 ~~~~> POST with AJAX for page.php

PHP gets the array and then use the function with each result of #divclassID

require "phpfunction.php";

$array = array received from AJAX;

for each #divclassID => $key {
getFunction($key)
}

After, rebuild a json array and print this;

文字说明:

1º) 对于每个 .divclass,构建一个包含所有 $(this).attr("ID"); 的数组(每个 .divclass 的 ID)

2º) 将数组发送到page.php;

3º) page.php 接收数组并使用数组中列出的每个元素 ID 的 php 函数;

请问,有可能吗?

【问题讨论】:

  • page.php 是做什么的?

标签: javascript php jquery arrays


【解决方案1】:

为客户端创建一个页面并在页面中编写一些jQ代码:

$(function(){
    var ids = [];
    $(".divclass").each(function() {
        ids.push($(this).attr('id')); // Push into JS array
    });
    $.post('page.php',{ids:ids},function(){
        alert('Horay, the data sent');
    });
});

page.php:

 <?php
 require "phpfunction.php";
 $ids = $_POST['ids']; // The $ids contains array of ID as you expected
 ?>

很简单好吗?你呢?

【讨论】:

  • 谢谢,但我必须在PHP函数中使用数组循环
猜你喜欢
  • 2019-09-13
  • 1970-01-01
  • 2017-10-02
  • 1970-01-01
  • 2015-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多