Jquery 我想用.load将页面内容加载到变量中,然后向其发出警报

Jquery 我想用.load将页面内容加载到变量中,然后向其发出警报,jquery,Jquery,但是下面的代码不起作用。submit.php:echo“Hi” $(文档).ready(函数(){ $(“#按钮”)。单击(函数(){ var输入; load(“submit.php”); 警报(输入); }); }); 请检查jquery$.post 还要查看jquery api文档以供进一步参考 通常ajax请求如下所示 $.ajax({ type: 'POST', url: 'sample.php', data: data, success: function(respo

但是下面的代码不起作用。submit.php:echo“Hi”


$(文档).ready(函数(){
$(“#按钮”)。单击(函数(){
var输入;
load(“submit.php”);
警报(输入);
});
});

请检查jquery$.post

还要查看jquery api文档以供进一步参考

通常ajax请求如下所示

$.ajax({
  type: 'POST',
  url: 'sample.php',
  data: data,
  success: function(response){ alert(response); },
  dataType: dataType
});
$('#result').load('ajax/test.html');
sample.php

<?
    echo "hai";
?>


$load的演示

请检查jquery$.post

还要查看jquery api文档以供进一步参考

通常ajax请求如下所示

$.ajax({
  type: 'POST',
  url: 'sample.php',
  data: data,
  success: function(response){ alert(response); },
  dataType: dataType
});
$('#result').load('ajax/test.html');
sample.php

<?
    echo "hai";
?>

演示$.load

您必须像这样使用.load()

$.ajax({
  type: 'POST',
  url: 'sample.php',
  data: data,
  success: function(response){ alert(response); },
  dataType: dataType
});
$('#result').load('ajax/test.html');
不向变量返回任何内容。 使用jQuery的、函数。

您必须像这样使用.load()

$.ajax({
  type: 'POST',
  url: 'sample.php',
  data: data,
  success: function(response){ alert(response); },
  dataType: dataType
});
$('#result').load('ajax/test.html');
不向变量返回任何内容。
使用jQuery的、函数。

首先,您应该了解jQuery是一个扩展javascript功能的框架。要使用它,必须有jquery对象。您已经声明了javascript变量,并且正在尝试对其调用jquery函数

如果您想要一个带有结果的变量,可以执行以下操作:

jQuery.get("submit.php", function(response) {
   //here you have response that contains submit.php response
   alert(response);
});

抱歉,我刚刚注意到@Dhiraj的答案。这种方法只需使用get witch就可以完成同样的事情,只需将“POST”切换到“get”即可完成他的答案

首先,您应该了解jQuery是一个扩展javascript功能的框架。要使用它,必须有jquery对象。您已经声明了javascript变量,并且正在尝试对其调用jquery函数

如果您想要一个带有结果的变量,可以执行以下操作:

jQuery.get("submit.php", function(response) {
   //here you have response that contains submit.php response
   alert(response);
});

抱歉,我刚刚注意到@Dhiraj的答案。这种方法只需使用get witch就可以完成同样的事情,只需将“POST”切换到“get”即可完成他的答案

为什么你认为一个空变量(“输入”)有一个load()方法?为什么你认为一个空变量(“输入”)有一个load()方法?