在jquery函数中发送一个php页面的值 [英] Take a value in php page sent with jquery function

查看:55
本文介绍了在jquery函数中发送一个php页面的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在脚本开始的这个html页面中,我在php页面发送变量fin的值( http://sat3.altervista.org/index.php?valore= + fin)。在这个php页面中,我试图采用变量的值,但是我没有成功。帮助我吗?
$ b $ pre $ <!doctype html>
< html>
< head>
< title>解析< / title>
< script type =text / javascriptsrc =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>')); (数据Apertura:'+ data [i] [Data Apertura]));
$('body')。append($('< p>
}

});

< / 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);



//编辑:定义一个数组来保存各个行
$ data = array();

while(!feof($ file_handle)){

//这里我拿了这个值,但它不包含任何
$ 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]);

//编辑:将行添加到数组
$ data [] = $ arr;
}

}

//编辑:将数组编码为JSON数组对象
echo json_encode($ data);

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



fclose($ file_handle);



?>


解决方案

jQuery参考 http://api.jquery.com/jQuery.getJSON/ 表示
的第二个参数是 A用这个请求发送给服务器的纯对象或字符串。



试试这个:

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

$ .getJSON(url,getVars,function(data){
//其余代码
});

< / script>

并让我们知道:)

编辑



关于你的PHP代码,你必须把这个 $ myValue = $ _GET [valore]; 在您的之前开始。


In this html page at the begin of the script i send the value of variable fin at the php page (http://sat3.altervista.org/index.php?valore="+ fin). In this php page i tried to take the value of variable but i didn't have success. Someone can help me?

<!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>

This is the php page:

<?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);



?>

解决方案

jQuery reference here http://api.jquery.com/jQuery.getJSON/ says that second argument is "A plain object or string that is sent to the server with the request."

Try this:

<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>

And let us know :)

EDIT

Regarding your PHP code, you have to put this $myValue = $_GET["valore"]; before your while begins.

这篇关于在jquery函数中发送一个php页面的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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