загрузить JpGraph на php-странице

Я хочу загрузить jpgraph на другую php страницу, используя ajax или javascript. Я успешно показываю график на отдельной странице php, но я хочу показать график, полученный от страницы Graphs.php до страницы index.php. Я пытался, но не преуспел.

index.php

$('#submitG').click(function(e) {
    e.preventDefault();
    // document.getElementById('content1').style.display = 'none';
    alert("gfh"+$('#startG').val()+$('#endG').val());
    $('#cont').load('<img src="view.png">').fadeIn("slow");
    alert("completed");
});

<form >
    <input name="startG" type="date" id="startG"  required/></div>
    <input name="endG" type="date" id="endG" required/></div>
    <input type="submit" value="Show Graph" id="submitG"/>
</form>

ОБНОВЛЕНИЕ:

//это мой div, в который я хочу загрузить изображение

<div id="cont"></div>

Графики.php

<?php
    include("DBConfig.php"); 
    require_once ('/src/jpgraph.php');
    require_once ('/src/jpgraph_line.php');
    $ph1=array();
    $ph2=array();
    $ph3=array();
    $sDate= $_POST['startDateG'];
    $eDate=$_POST['endDateG'];
    $datee1 = new DateTime($sDate);
    $date1=$datee1->format('d-m-y'); // 31-07-2012
    //echo "&nbsp;&nbsp;&nbsp;&nbsp;";
    $datee2 = new DateTime($eDate);
    $date2=$datee2->format('d-m-y'); // 31-07-2012
    if ($conn) {     
        //echo 'Connected';
        $stid = oci_parse($conn, "SELECT * FROM table");
        oci_execute($stid);
        while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
            array_push($d1, $row['c1']);
            array_push($d2, $row['c2']);
            array_push($d3, $row['c3']);
        }
    }

    $datay1 = array(20,15,23,15);
    $datay2 = array(12,9,42,8);
    $datay3 = array(5,17,32,24);

    // Setup the graph
    $graph = new Graph(1000,450);
    $graph->SetScale("textlin");

    $theme_class=new UniversalTheme;

    $graph->SetTheme($theme_class);
    $graph->img->SetAntiAliasing(false);
    $graph->title->Set('Single Pahse');
    $graph->SetBox(false);

    $graph->img->SetAntiAliasing();

    $graph->yaxis->HideZeroLabel();
    $graph->yaxis->HideLine(false);
    $graph->yaxis->HideTicks(false,false);

    $graph->xgrid->Show();
    $graph->xgrid->SetLineStyle("solid");
    $graph->xaxis->SetLabelMargin(2);
    $graph->xgrid->SetColor('#E3E3E3');

    // Create the first line
    $p1 = new LinePlot($d1);
    $graph->Add($p1);
    $p1->SetColor("#6495ED");
    $p1->SetLegend('Line 1');

    // Create the second line
    $p2 = new LinePlot($d2);
    $graph->Add($p2);
    $p2->SetColor("#B22222");
    $p2->SetLegend('Line 2');

    // Create the third line
    $p3 = new LinePlot($d3);
    $graph->Add($p3);
    $p3->SetColor("#FF1493");
    $p3->SetLegend('Line 3');

    $graph->legend->SetFrameWeight(1);

    // Output line
    $graph->Stroke();

    oci_close($conn);

?>

person nagi    schedule 08.09.2015    source источник


Ответы (1)


Попробуйте что-то вроде этого:

$('#submitG').click(function(e) {
    e.preventDefault();
    alert("gfh"+$('#startG').val()+$('#endG').val());
    $('#cont').load(
        'Graphs.php',
        {
            startG: $('#startG').val(),
            endG: $('#endG').val(),
        },
        function() {
            alert("completed");
            $(this).fadeIn("slow"); // Or $('#cont').fadeIn("slow");
        }
    );
});

Поскольку jQuery.load извлекает данные через GET, вы должны использовать $_GET['startDateG'] вместо $_POST['startDateG'] в своем PHP скрипте. В противном случае вам следует использовать jQuery.post.

person mario.klump    schedule 08.09.2015
comment
он не показывает изображение, он показывает данные, такие как: �PNG IHDR���it� IDATx���y\SW�8�'�F�K٭��V���j;�tt�:u��� ���}�.3S_g�kgF���NW�jw;v�kmm�P���V0aQ0 IȾ���p�$!���›��|���s���P| ���si�@B!�Bc�j!�B!ty�#�B!4` - person nagi; 08.09.2015
comment
Является ли #cont вашим тегом ìmg? Я не могу найти его в коде HTML вашего вопроса. - person mario.klump; 08.09.2015
comment
решено: я использовал тег img в Graphs.php и загрузил его в div. - person nagi; 08.09.2015
comment
Спасибо за помощь. я делал ошибку, не загружая изображение, а загружая строку - person nagi; 08.09.2015