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 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分