2

Basically, I'm having a javascript file in which there is a ajax function which has its url pointing to a php file named getfile.php.

In this php file, I'm reading and storing content of another php file with url:

http://xxx.xxx.x.xx/php/getpage.php?mode=opensvc&fx=getPositions&date=2014-04-02&time=0&lat=27.219722&lng=78.019616/

having data in json form to utilise in my javascript file.

I am having a problem as now I want to get the json data from php file dynamically by appending date from html input tag to getfile.php, so that the json data will be available according to date as it will append in url to dynamically change the date attribute.

our getfile.php code is:-

$homepage =file_get_contents('http://xxx.xxx.x.xx/php/getpage.php?mode=opensvc&fx=getPositions&date=2014-04-02&time=0&lat=27.219722&lng=78.019616/');
echo $homepage;

ajax code in javascript file:-

$.ajax({
    url: "getfile.php",
    type: "POST",
    dataType: 'json',
    success: function (data) {
        var i = 0;
        while (data[i]) {
            lat[i] = data[i].latitude;
            lng[i] = data[i].longitude;
            latlng1[i] = new google.maps.LatLng(lat[i], lng[i]);
        }
    }
});

If I change the date attribute in the url then the json data from that url is different so I want to provide the date dynamically.

3
  • Could you post some html and javascript of what you are doing now? This way it is clearer what exactly you want. You could also create a jsfiddle to let us test your code. Commented Jul 29, 2014 at 7:06
  • I think the relevant code is in getfile.php. Show this code. Commented Jul 29, 2014 at 8:04
  • now i have added my source code on which i am working. check it out! Commented Jul 29, 2014 at 9:49

2 Answers 2

2

you can dynamically declare a date variable as global in javascript file so that you can access it in php file and also you can get its value from html element. You can do it like this in javascript file:-

var data={};
data['date']="12-2-2014";
$.ajax(
{
url: "getfile.php",
type: "POST",
data: "data",
dataType: 'json',
success: function (data) {
    var i = 0;
    while (data[i]) {
        lat[i] = data[i].latitude;
        lng[i] = data[i].longitude;
        latlng1[i] = new google.maps.LatLng(lat[i], lng[i]);
    }
}

});

Then in php file you have to write the following code:-

 $d= $_POST['date'];
 $homepage =file_get_contents('http://xxx.xxx.x.xx/php/getpage.php?mode=opensvc&fx=getPositions&date='.$d.'&time=0&lat=27.219722&lng=78.019616/');
 echo $homepage;
Sign up to request clarification or add additional context in comments.

Comments

0
function GetFile(){
    var dat = $('YOUR FIELD WITH DATE VALUE').val();
        $.post("getfile.php", {dat: ""+ dat +""}, function(data){
            if(data.length >0) {
                $('YOUR RESULT FIELD').val(data);
            }
        });

}

with this function you actualy send data from your date text field, so all you gotta do is echo data you need in your getfile.php and result will be in your result field. If I understood question well

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.