jquery - Ajax not making changes -


i'm working through book on php , jquery , i've encountered problem ajax, in not post it's changes , display them.

    <head>     <meta charset="utf-8" />     <title>testing jquery</title> </head> <body>     <p>hello world!</p>     <p class="foo">another paragraph, 1 ahs class.</p>     <p><span>this span in paragraph</span></p>     <p id="bar">paragraph id.         <span class="foo">and sentence in span</span>     </p>     <script src="jquery.validate.min.js"></script>     <script src="jquery/ajax.js"></script>     <script src="jquery/jquery-1.8.3.min.js"></script>      <form action="#" method="post">         <fieldset>             <legend>sign form</legend>             <label for="name">name</label><br/>             <input name="name" id="name" type="text" /><br/>             <label for="password">password</label><br/>             <input name="password" id="password"                    type="password" /><br/>             <label>                 <input id="mycomp" type="radio" name="loc" />                 i'm on computer.             </label><br/>             <label>                 <input id="shared" type="radio" name="loc" checked="checked" />                 i'm on shared computer.             </label>             <input type="submit" value="log in" /><br/>             <label>                 <input id="signedin" type="checkbox" name="notify"                        disabled="true"/>                 keep me signed in on computer.             </label><br/>         </fieldset>     </form>  </body> </html> 

here code test site. it's exceedingly simple yet ajax query won't modify it:

    $.ajax({   "type":"post",   "url":"ajax.php",   "data":"var1=val1&var2=val2",   "success":function(data){     $("#bar")     .css("background","yellow")     .html(data);   } }); 

i'm running through firebug console, , seems functioning correctly, nothing happening.

well, try explain all. first, when want send form ajax, don't use submit , attributes of tag . assign function button or element submit form, , function call ajax, example.

with html, jquery code:

$('input[type=submit]').click(submitform); function submitform(){ $.ajax({    "type":"post",    "url":"ajax.php",    "data":"var1=val1&var2=val2",    "success":function(data){        $("#bar")        .css("background","yellow")        .html(data);    }  }); } 

and if post, must send variables in array or this:

"data": {    var1:val1,    var2:val2  } 

you receive in $_post[var1] , $_post[var2] in ajax.php.

so javascript/jquery code this:

$('input[type=submit]').click(submitform); function submitform(){ $.ajax({   "type":"post",   "url":"ajax.php",   "data": {        var1:val1,        var2:val2      },   "success":function(data){     $("#bar")     .css("background","yellow")     .html(data);   } }); } 

if have question, tell me. hope useful you.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -