开发者

sending ajax twitter results to other PHP file

I want to send twitter results from a login system (that gets the geolocations from the browser) and i want to send it to a different php file to process it and send it to the mysql database.

here's my function:

function twitterMarkers(lat, long) {
var returnLat = new Array(0);
var returnLong = new Array(0);
var returnTweet = new Array(0);
var returnTotal = new Array();

$.ajax({
    dataType: 'jsonp',
    url: 'http://search.twitter.com/search.json?&geocode=' + lat + ',' + long + ',1mi&rpp=100',
    success: function(data) {
        //console.log("hoi");
        $.each(data.results, function(i, tweets) {

            var tweetGeo = tweets.geo;

            if (tweetGeo != null) {

                // console.log(tweetGeo.coordinates[0]);
                // return tweetGeo.coordinates;
                returnTotal.push(tweetGeo.coordinates[0]);
                returnTotal.push(tweetGeo.coordinates[1]);
                returnTotal.push(tweets.text);
            }
            if (tweets.error) {
                alert("error");
            }
        });
        //console.log(returnTotal);

        if (returnTotal.length > 1 ){
        $("#jsondata").val(JSON.stringify(returnTotal));
        console.log(document.getElementById("jsondata").value);
//return ;
}

    }

});

 };

I've tried to make an array out of it by returning the data, but i only get an empty array. How do i send this correctly, because i understand now that it takes some time to process the ajax data. then i want to user to click login after the location data is found and send it by using this:

 <form id="postform" name="postform" action="inc/php/login.php" metho开发者_如何转开发d="post" enctype="multipart/form-data" > 
    <div class="forminput">
        <label for="title"><h5>Enter your name</h5></label><br />
        <input type="text" id="name" name="name" value="<?php echo $name;?>" />
            <input type="hidden" id="nameUser" name="nameUser" value="<?php setcookie("nameUserVal", $name);?>" /

            <div class="forminput">
    <input type="hidden" id="jsondata"  />
<input type="submit" value="Login" />

I've tried asking the data in the other php file, but it doesn't work:

 $data = $_POST['jsondata'];
 print_r($data);


I guess you should replace

<input type="hidden" id="jsondata"  />

with

<input type="hidden" name="jsondata" id="jsondata"  />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜