使用jQuery AJAX获取语法错误

时间:2013-03-02 02:28:29

标签: php javascript jquery

我是jQuery的新手,我试图从我发现使用AJAX的网站上复制一个例子,我需要将PHP变量传递给另一个PHP页面而不刷新整个页面。我在下面提出了以下代码,但是我收到了语法错误

Uncaught SyntaxError: Unexpected token )

这是我的代码:

$("Button").click(function(){
    var textBox = $("textBox").val();
$.post("script.php",
    {textBox: textBox},
     function(data,status)
    )};
)};

我的PHP页面:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  <head>
    <script type='text/javascript' src='script.js'></script>
    <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></$
    <title>LCD Display</title>
  </head>
  <body>

        <form id="lcd" action="script.php" method="post">
     <input name='textBox' type='text' />
     <input type='submit' id= 'Button' value='Press to see something cool'/>
     </form>
    <div id='ResponseDiv'>
    </div>

    <iframe id="video" src="http://192.168.0.11:8081" height="120" width="160"></iframe>

  </body>
</html>

我也遇到以下错误,但我认为它们可能与语法错误有关:

Resource interpreted as Document but transferred with MIME type multipart/x-mixed-replace: "http://192.168.0.11:8081/".
Resource interpreted as Document but transferred with MIME type image/jpeg: "http://192.168.0.11:8081/".

2 个答案:

答案 0 :(得分:2)

结束标记:

 )};

应该是这样的:

$("Button").click(function(){
var textBox = $("textBox").val();
$.post("script.php",
    {textBox: textBox},
      function(data,status){
   });
});

和脚本顺序将是这样的,并且关注结束</$

<head>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'>
</script>
<script type='text/javascript' src='script.js'></script>
<title>LCD Display</title>

答案 1 :(得分:0)

 $.post("script.php",
     {textBox: textBox},
     function(data,status){}
   );

另请阅读:http://api.jquery.com/jQuery.post/