jQuery Ajax返回整个页面 [英] jQuery Ajax returns the whole page

查看:380
本文介绍了jQuery Ajax返回整个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jquery-ajax函数,它将数据发送到php脚本,问题是返回值,它返回整个页面而不是单个值.

I have a jquery-ajax function that sends data to a php script and the problem is with the return value, it returns the whole page instead of single value.

感谢您的时间和帮助.

$("#ajaxBtn").click(function(){
  var inputText = $("#testText").val();

  $.ajax({ type: "POST",
    url: "index.php",
    data: "testAjax="+inputText,
    dataType: "html",
    success: function(html){
      alert(html);
    }
  });
});         

推荐答案

就是这样.您正在通过AJAX请求index.php,因此您将获得index.php的任何内容.

That's how it works. You're requesting index.php via AJAX, so you'll get whatever the contents of index.php are.

如果您想要一个特定的值,请创建一个仅输出该值的新PHP页面,然后请求该URL的内容.

If you want a particular value, make a new PHP page that outputs just that value, and request that URL's contents instead.

这篇关于jQuery Ajax返回整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆