weixin_33736048 2014-10-22 13:20 采纳率: 0%
浏览 19

jQuery-为什么不起作用?

This is the code of index.php that displays a form with a 'Connect Me' button. I suppose that when user will press that button, it will change to 'Connecting...' and will send the POST data to startTransaction.php script (that is in the same directory) and will show a message after the POST data is sent, or else will display an error message if any error occurs. But when I press "Connect Me" it just reloads the page. Contents of index.php are:

< !doctypehtml > < htmllang = "en" > < head > < metacharset = "UTF-8" / > < title > Freecalls, nosignuprequired! < / title > < linkrel = "stylesheet"href = "css/style.css" />
< scriptsrc = "js/jquery.min.js" > </script>
<script src="js/jquery.ui.shake.js"></script>
<script>
$(document).ready(function() {

$('#call').click(function()
{
var caller=$("#caller").val();
var receiver=$("#receiver").val();
var dataString = 'caller='+caller+'&receiver='+receiver;
if($.trim(caller).length>0 && $.trim(receiver).length>0)
{


$.ajax({
        type: "POST",
        url: "startTransaction.php",
        data: dataString,
        cache: false,
        beforeSend: function(){ $("#call").val('Connecting...');},
        success: function(data){
        if(data)
        {
         $('#box').shake();
 $("#call").val('Connect')
 $("#error").html("<span style='color:#cc0000'>All set! </span> We'll call you in 5 minutes to connect you. ");

        }
          else
        {
         $('#box').shake();
 $("#call").val('Connect')
 $("#error").html("<span style='color:#cc0000'>Error:</span> An error occured.");
        }
        }
        });

}
return false;
});


});
</script>
</head>

<body>
<div id="main">
<h1>Start making free calls now!</h1>

<div id="box">
<form action="" method="post">
<label>What's your number?</label> 
<input type="text" name="caller" class="input" autocomplete="off" id="caller"/>
<label>And your friend's? </label>
<input type="text" name="receiver" class="input" autocomplete="off" id="receiver" />
<br/>
<input type="submit" class="button button-primary" value="Connect Me!" id="connect"/> 
<span class='msg'></span> 

<div id="error">

</div>
// html closing tags here

Please tell me where I am wrong :)

  • 写回答

3条回答 默认 最新

  • weixin_33744854 2014-10-22 13:23
    关注

    your script tag to include jquery seems incorrect

    < scriptsrc = "js/jquery.min.js" > </script>
    

    should be (missing space between script and src)

    <script src = "js/jquery.min.js" > </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么