Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用Jquery和Ajax获取HTTP请求_Php_Ajax_Jquery_Get - Fatal编程技术网

Php 使用Jquery和Ajax获取HTTP请求

Php 使用Jquery和Ajax获取HTTP请求,php,ajax,jquery,get,Php,Ajax,Jquery,Get,我有下面的代码,正在尝试使用Jquery和Ajax通过GET HTTP请求传递数据。当在文本框中输入“示例”并单击“Go”时,我希望“示例”会返回到反馈分区中。但是没有返回任何内容。如果您能提供任何帮助,我将不胜感激。谢谢 文件名为“trial.php” 文件名为“File.php” 用document.ready事件包装ajax.js: $(document).ready(function () { $('#button').click(function () { va

我有下面的代码,正在尝试使用Jquery和Ajax通过GET HTTP请求传递数据。当在文本框中输入“示例”并单击“Go”时,我希望“示例”会返回到反馈分区中。但是没有返回任何内容。如果您能提供任何帮助,我将不胜感激。谢谢

文件名为“trial.php”

文件名为“File.php”


用document.ready事件包装ajax.js:

$(document).ready(function () {
    $('#button').click(function () {
        var string = $('#string').val();

        $.get('file.php', { input: string }, function (data) {  
            $('#feedback').text(data);
        });
    });
});
如果未包含任何jquery文件,请使用tage中顶部scipt函数中的任何jquery.min.js文件,如:
然后修改javascript函数,如下所示:
$(文档).ready(函数(){
$(“#按钮”)。单击(函数(){
var string=$('#string').val();
$.get('file.php',{input:string},函数(数据){
$(“#反馈”)。文本(数据);
});
});
});

也许,您可以在php端打印数据,看看发生了什么。请避免调用您的变量字符串,这可能会导致许多疯狂的错误。您是否使用firebug检查过它?结果是什么?如果执行
print\r($string)
,您会得到什么?还可以通过执行
console.log(数据)
alert(数据)来检查
get
请求的成功回调中得到了什么
$('#button').click(function()
{
var string = $('#string').val();

$.get('file.php', { input: string }, function(data) {  
$('#feedback').text(data);
});
});
<?php
if(isset($_GET['input']))
{
$string = $_GET['input'];
echo strtolower($string);
}
?>
$(document).ready(function () {
    $('#button').click(function () {
        var string = $('#string').val();

        $.get('file.php', { input: string }, function (data) {  
            $('#feedback').text(data);
        });
    });
});
    /*Try this*/
    $(document).ready(function(){
    $('#button').click(function()
    {

    var dataToSend={ input:$('#string').val() };

    $.ajax(url:'file.php', data:dataToSend,dataType:'html',type:'GET',success:function(data) {  
    $('#feedback').text(data);
    });
    });
});
If you were not included any jquery file then please use any of jquery.min.js file at the top scipt function within <head> tage like:

<script src="jquery-1.3.2.min.js" language="javascript" type="text/javascript"></script>

And then modify your javascript function as given:

$(document).ready(function(){
$('#button').click(function(){
  var string = $('#string').val();

  $.get('file.php', { input: string }, function(data) {  
     $('#feedback').text(data);
   });
  });
});