douna1941
2013-03-02 02:28
浏览 55

使用jQuery AJAX获取语法错误[关闭]

I am new to jQuery and am trying to copy an example from a website I found that uses AJAX I need to take the PHP variable and pass it to another PHP page without refreshing the entire page. I have come up with the following code below but I am getting a syntax error

Uncaught SyntaxError: Unexpected token )

Here is my code:

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

My PHP page:

<!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>

I am also getting the following errors but I think they may be related to the syntax error:

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/".

图片转代码服务由CSDN问答提供 功能建议

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

Uncaught SyntaxError:Unexpected token)

这是我的代码:

  $(“Button”)。click(function(){
 var textBox = $(“textBox”)。val(); \  n $ .post(“script.php”,
 {textBox:textBox},
 function(data,status)
)}; 
)}; 
   
 \  n 

我的PHP页面:

 &lt;!DOCTYPE HTML PUBLIC“ -  // W3C // DTD HTML 4.01 // EN”“http://www.w3  .org / TR / html4 / strict.dtd“&gt; 
&lt; head&gt; 
&lt; script type ='text / javascript'src ='script.js'&gt;&lt; / script&gt; 
&lt; script  type ='text / javascript'src ='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'>&lt; / $ 
&lt; title&gt; LCD Display&lt;  ; / title&gt; 
&lt; / head&gt; 
&lt; body&gt; 
 
&lt; form id =“lcd”action =“script.php”method =“post”&gt; 
&lt; input name =  'textBox'type ='text'/&gt; 
&lt; input type ='submit'id ='Button'value ='按下以查看酷炫的内容'/&gt; 
&lt; / form&gt; \  n&lt; div id ='ResponseDiv'&gt; 
&lt; / div&gt; 
 
&lt; iframe id =“video”src =“http://192.168.0.11:8081”height =“120”width =  “160”&gt;&lt; / iframe&gt; 
 
&lt; / body&gt; 
&lt; / html&gt; 
   
 
 

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

 资源被解释为Document但是使用MIME类型传输multipart / x-mixed-replace:“http://192.168.0.11  :8081 /“。
Resource解释为文档,但使用MIME类型image / jpeg传输:”http://192.168.0.11:8081/".
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douhui8025 2013-03-02 02:40
    已采纳

    Your closing tags:

     )};
    

    should be this way:

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

    and script order will be this way and mind the closing </$:

    <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>
    

    打赏 评论
  • douzhi1937 2013-03-02 02:33
     $.post("script.php",
         {textBox: textBox},
         function(data,status){}
       );
    

    Also read : http://api.jquery.com/jQuery.post/

    打赏 评论

相关推荐 更多相似问题