dongxinche1264 2015-06-25 13:32
浏览 71
已采纳

JQuery嵌入了php echo。 没有成功

Hello i want to use Jquery ajax

echo "$(document).ready(function() {
          $(\"#submit\").click(function(){
                var n = $(\"#n\").val();  

                jQuery.ajax({
                    type: \"GET\",
                    url: \"function.php\",
                    data: \"n=\"+n,
                    success: function(results)
                    {
                        alert(n);                       

                    }
               });
          });
      });";

but never it shows the alert(n);

Can you help me?


Edit: I try to do it with only js but dont work too.. here is it.

<script>
  var n = $('#n').val(); 
  $(document).ready(function() {
    $('#submit').click(function(){
      var n = $("#n").val();

      $.ajax({
        type: 'GET',
        data: "n=" + n,
        url: 'function.php',
        success: function (results) {
            alert(results);
            alert("some");
        }
      });
    });
  });
</script>

<form action='' method='post'>
  <select name='n'  id='n'>
    <option value='Lusiana'>Lusiana</option>
  </select>
  <input id='submit' name='submit' type='submit' value='Go'>
</form>

I'm using this code: https://github.com/papalevski/jQuerySlider/tree/master/jQuerySlider

the php is:

<?php
  $n = ( isset($_GET['n']) ? $_GET['n'] : "");
  echo $n;
?>

展开全部

  • 写回答

2条回答 默认 最新

  • dongpingwu8378 2015-06-25 13:42
    关注

    please, indent your code, it will be less difficult to read, data should be sent like data: {n:"value"}, in your case i think this must work data:{n:\""+n+"\"},

    echo "$(document).ready(function() {
              $('#submit').click(function(){
                  var n = $('#n').val();  
                  jQuery.ajax({
                      type: 'GET',
                      url: 'function.php',
                      data: {n:n},
                      success: function(results){                      
                          alert(n)
                      }
                  });
              });
          });";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部