www.webdeveloper.com
Results 1 to 2 of 2

Thread: Get data from php

  1. #1
    Join Date
    Mar 2011
    Posts
    1

    Get data from php

    Hi frnds,

    I am a newbie to AJAX.The task is I have to get the data from a php file and store it in a javascript variable. I have gone through many examples but didn't find helpful.
    I am giving a pseudo html code here:

    <html>
    <head>
    <script>
    function ajaxfunction()
    {
    //code for httprequest
    call the php file
    declare a variable and get the response of php
    //return the variable
    }
    </script>
    </head>
    <body>
    //my code for displaying a map
    mainvariable=ajaxfunction();//storing the value of subvariable(data from php) in mainvariable
    //use the mainvariable and do the remaining task
    <body>
    </html>


    My php code:
    <?php
    $file=fopen("datapoints.txt","r");
    $read=fread($file,filesize("datapoints.txt"));
    fclose($file);
    echo $read;
    ?>

    the problem here is I dont have any form variables in my html file to use while calling php file. simply when the page loads, "ajaxfunction()" should be called and get data from php and store in a variable................

    I guess you can understand my problem

    Any help is greatly appreciated

  2. #2
    Join Date
    Oct 2003
    Location
    Andover, UK
    Posts
    947
    I didn't completely follow what you're doing but, simply, to get a value back via AJAX from PHP, and store it in a var:

    PHP:
    PHP Code:
    <?php echo "I'm a return value"?>
    JS (with jQuery)
    Code:
    $.ajax({url: 'php_page.php', success: function(ajaxResponse) { someVar = ajaxResponse; }});

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles