weixin_33743880 2015-05-12 08:34 采纳率: 0%
浏览 14

jQuery AJax结果回显PHP

I must to check the result of Ajax are same with some PHP variable value. Is there anyway to do this?

Thank you in advance for help.

My Ajax HTML:

<?php
$x = '<p id="ip"></p>';
$y = '2_2_1_3';

if($x == $y){
  echo $x;
}
?>

<a id="input" href="#">Get value<input type="hidden" value="2_2_1_3"></a>

<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
jQuery(document).ready(function(){
  $("#input").on("click", function(){
    $.ajax({
      type: 'POST',
      url: "ip2.php", 
      data:'ip=' + $(this).parent().find('input').val(),
      success: function(data){
      $("#ip").html(data);
      }
    });
  });
});
</script>

The PHP script:

<?php
if($_POST['ip'] >= 0){
  $ip = $_POST['ip'];  
  echo $ip;  
}
?>
  • 写回答

2条回答 默认 最新

  • weixin_33720452 2015-05-12 08:45
    关注

    I'm not entirely sure what you want to do, but you can always send your post data as an object in javascript, for simplicity you can use the post function.

    Example:

        $.post( "ip2.php", { ip: $(this).parent().find('input').val() }, function( data ) {
          console.log( data );
        });
    

    More info: https://api.jquery.com/jquery.post/ https://api.jquery.com/jQuery.ajax/

    评论

报告相同问题?

悬赏问题

  • ¥15 用matlab或python实现多个表格合并单元格
  • ¥15 gojs 点击按钮node的position位置进行改变,再次点击回到原来的位置
  • ¥15 计算决策面并仿真附上结果
  • ¥20 halcon 图像拼接
  • ¥15 webstorm上开发的vue3+vite5+typeScript打包时报错
  • ¥15 vue使用gojs,需求在link中的虚线上添加方向箭头
  • ¥15 CSS通配符清除内外边距为什么可以覆盖默认样式?
  • ¥15 SPSS分类模型实训题步骤
  • ¥100 求ASMedia ASM1184e & ASM1187e 芯片datasheet/规格书
  • ¥15 求解决扩散模型代码问题