【问题标题】:Take a value in php page sent with jquery function在使用 jquery 函数发送的 php 页面中取一个值
【发布时间】:2014-06-30 19:17:00
【问题描述】:

在脚本开头的这个 html 页面中,我在 php 页面 (http://sat3.altervista.org/index.php?valore="+ fin) 发送变量 fin 的值。在这个 php 页面中,我尝试获取变量的值,但我没有成功了。有人可以帮助我吗?

<!doctype html>
    <html>
    <head>
        <title>Parsing</title>
        <script type="text/javascript" src="jquery-2.1.0.min.js"></script>


    </head>
    <script>
        var fin = "SAT000000002575";
        url = "http://sat3.altervista.org/index.php?valore="+ fin,

        data = {
            get_param: 'value'
        };


        $.getJSON(url, data, function (data) {
             for (var i = 0; i < data.length; i++) {
                var lin = data[i]["Nr SAT"];
                $('body').append($('<p>').html('Numero Sat: <a href ="http://sat3.altervista.org/NuovoFile.html?id=' + lin + '">' + data[i]["Nr SAT"] + '</a>'));
                $('body').append($('<p>').html('Data Apertura: ' + data[i]["Data Apertura"]));
            }

        });

    </script>

        <body>
            <header>

            </header>


        </body>

    </html>

这是php页面:

<?php

// Sopprimo gli errori del php
error_reporting(0);

// Includo la libreria
require_once 'excel_reader2.php';



$file_handle = fopen("leggimi2.csv", "r");



//EDIT: Define an array to hold individual lines
$data = array();

while (!feof($file_handle) ) {

    //HERE I TAKE THE VALUE BUT IT DON'T CONTAIN NOTHING
    $myValue = $_GET["valore"];


    $line_of_text = fgetcsv($file_handle, 1024);
    if ($line_of_text[0] == $myValue)
    {
        $arr = array('Nr SAT' => $line_of_text[0],'Data Apertura' => $line_of_text[13], 'Tipo Servizio' => $line_of_text[1], 'Stato SAT' => $line_of_text[2],'Marca Terminale' => $line_of_text[4], 'Modello Terminale' => $line_of_text[5], 'IMEI guasto' => $line_of_text[6],'IMEI consegnato' => $line_of_text[7],'Famiglia guasto' => $line_of_text[8],'Descrizione guasto' => $line_of_text[9] );

        //EDIT: Add the line to the array
        $data[] = $arr;
    }

}

//EDIT: Encode the array as a JSON array of line objects
echo json_encode($data);

//$myValue = isset($_GET['myValue']) ? $_GET['myValue'] : '';



fclose($file_handle);



?>

【问题讨论】:

  • 哪里失败了?有哪些回应?发送的查询是否正确?请提供我们能够帮助您的信息。我建议使用 Firebug 或 Chrome 调试器来帮助自己或提供所需的信息。
  • 我添加了 php 页面。我认为php页面中的值没有出现。帮帮我!!
  • 有人可以帮帮我吗??????

标签: php html


【解决方案1】:

这里的 jQuery 参考 http://api.jquery.com/jQuery.getJSON/ 说 第二个参数是“随请求发送到服务器的普通对象或字符串。

试试这个:

<script type="text/javascript">
var fin = "SAT000000002575",
url = "http://sat3.altervista.org/index.php",
getVars = {
    valore : fin
};

$.getJSON(url, getVars, function(data) {
    // rest of your code
});

</script>

让我们知道:)

编辑

关于你的 PHP 代码,你必须把这个 $myValue = $_GET["valore"]; before 你的 while 开始。

【讨论】:

  • 从 php 页面获取我用你的代码发送的值?
  • 你必须把这个$myValue = $_GET["valore"];放在你的while开始之前。
猜你喜欢
  • 2014-06-30
  • 2014-06-29
  • 2018-04-10
  • 1970-01-01
  • 2016-12-01
  • 1970-01-01
  • 2014-01-19
  • 2013-08-31
  • 2013-01-24
相关资源
最近更新 更多