0

我这里有问题。我需要进入$pilihdomainsearh_request.php才能search_response.php中使用 我还没有访问它。

我这样定义:

设置.php

 <?php
    $dbHost = "localhost";
    $dbUser = "root";
    $dbPass = "";
    $dbname = "skripsi";
    $pilihdomain=$_POST['cmake'];
    global $pilihdomain;
    ?>

search_request.php

 <script src='jquery.min.js'></script>
    <script>
        jQuery(document).ready(function($) {

            // Run when Search button is clicked
            $('#search_button').click(function(){

                // This can take a few seconds so display progress text
                $('#search_results').html('Searching Twitter...');

                // Get the value of the input field
                // Encode it for use in a URL
                var search_value = encodeURIComponent($('input[name=search_terms]').val());

                // Send the search terms to the server in an Ajax request
                // This URL is for illustration only
                // You MUST change it to your server
                $.ajax({
                    url: 'http://localhost/kejar/code/search_response.php?q=' + search_value,
                    success: function(data){

                        // Display the results
                        $('#search_results').html(data);
                    }
                })
            })
        });
    </script>
    <?php require_once 'settings.php'; ?>
    Search: 
    <input name='search_terms' autofocus='autofocus'/>
     <?php
    $db = mysql_connect($dbHost,$dbUser,$dbPass);
    mysql_select_db($dbname,$db);
    $sql = mysql_query("SELECT * FROM namaklasifier");
    while($row = mysql_fetch_array($sql)) {
        $clsfr = $row['username'];
        $sql = mysql_query("SELECT * FROM namaklasifier");
            echo '<select name="cmake" autofocus width="10">';
            echo '<option value="0">-Pilih Domain Klasifikasi-</option>';
            while($row = mysql_fetch_array($sql)) {
                echo '<option ' . ($clsfr==$row['username']) . ' value="'.$row['username'].'">'.$row['username'].'</option>'; 
        }
        echo '</select>';
    }

    ?>
    <button id='search_button'>Search</button>
    <div id='search_results'></div>

search_response.php

<

?php 
 require_once("uClassify.php");
 require_once 'settings.php';

    $uclassify = new uClassify();
    $uclassify->setReadApiKey('8DvvfxwKPdvjgRSrtsTSOawmQ0');
    $uclassify->setWriteApiKey('v4Us59yQFhf9Z0nGrQsrTtzBI5k');
if (!empty($_GET['q'])) {

    // Strip any dangerous text out of the search
    $search_terms = htmlspecialchars($_GET['q'].' -RT -@smartfrenworld -@smartfrencare -from:smartfrencare -from:smartfrenworld');

    // Create an OAuth connection
    require 'app_tokens.php';
    require 'tmhOAuth.php';
    $connection = new tmhOAuth(array(
      'consumer_key'    => $consumer_key,
      'consumer_secret' => $consumer_secret,
      'user_token'      => $user_token,
      'user_secret'     => $user_secret
    ));

    // Run the search with the Twitter API
    $http_code = $connection->request('GET',$connection->url('1.1/search/tweets'), 
                array('q' => $search_terms,
                'count' => 20,
                'lang' => 'in',
                'locale' => 'jakarta',
                'result_type' => 'recent'));

    // Search was successful
    if ($http_code == 200) {

        // Extract the tweets from the API response
        $response = json_decode($connection->response['response'],true);
        $tweet_data = $response['statuses']; 

        // Accumulate tweets from search results
        $tweet_stream = '';     
        foreach($tweet_data as $tweet) {

            // Ignore retweets
            if (isset($tweet['retweeted_status'])) {
                continue;
            }

        $resp = $uclassify->classify($tweet['text'], **$pilihdomain**, 'herlambangp');              
            $value = print_r($resp,true) ;   
            // Add this tweet's text to the results
            $tweet_stream .= $tweet['text'].' | '.$value.'<br/>';
        }

        // Send the result tweets back to the Ajax request
        print $tweet_stream;

    // Handle errors from API request
    } else {
        if ($http_code == 429) {
            print 'Error: Twitter API rate limit reached';
        } else {
            print 'Error: Twitter was not able to process that search';
        }
    }

} else {
    print 'No search terms found';
}

?>

谢谢你的帮助。

4

2 回答 2

0

您的文件应该返回 JSON,然后您可以使用它并使用 jquery 来填充您的字段。

于 2013-06-13T18:08:04.003 回答
0

变量范围不是这里的问题,因此您可以取出全局 $pilihdomain。

您能够访问该变量的值的唯一方法是将其作为 GET 或 POST 参数传递。

search_request.php

var pilihdomain = '<?php echo $pilihdomain ?>';
$.ajax({
    url: 'http://localhost/kejar/code/search_response.php?q=' + search_value + '&pilihdomain=' + pilihdomain,
    success: function(data){
        // Display the results
        $('#search_results').html(data);
    }
})

search_response.php中,

$pilihdomain = $_GET['pilihdomain'];
于 2013-06-13T18:08:04.160 回答