dqdt45183 2011-04-15 09:48
浏览 62
已采纳

如何从AJAX调用中返回变量?

Just a simple question (I think).

Have a look at the code in this fiddle: http://jsfiddle.net/d9wdM/1/

What I doing is creating a website as a personal project that let's the user enter any amount of names and e-mail addresses and once the form is submitted, a random name is selected from the names and an e-mail is sent to that person and also their name is outputted on the page.

I can get the AJAX call to work but I don't know how to pass the name variable back from process.php to index.php as all it can return is a 1.

I hope that makes sense, if it doens't please let me know and I will try and make it clearer.

Thanks again,

Martin

  • 写回答

3条回答 默认 最新

  • dongyao5186 2011-04-15 13:35
    关注

    Managed to solve it, changed the ajax call to:

    <script type="text/javascript">
        $(function() {
            $('.tearoundform').submit(function() 
            {
                 var query = $(this).serialize();
                 $('#form_results').fadeOut(500).addClass('ajax-loading');
                 $.ajax({
                     type: "GET",
                     url: "process.php",
                     data: query,
                     success: function(data)
                     {
                          $('#form_results').removeClass('ajax-loading').html(data).fadeIn(500);
                     }
                 });
            return false;
           });
        });
    </script>`
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)