在最后,我邀请大家参加新浪APP,就是新浪免费送大家的一个空间,支持PHP+MySql,免费二级域名,免费域名绑定 这个是我邀请的地址,您通过这个链接注册即为我的好友,并获赠云豆500个,价值5元哦!短网址是http://t.cn/SXOiLh我创建的小站每天访客已经达到2000+了,每天挂广告赚50+元哦,呵呵,饭钱不愁了,\(^o^)/
已标记关键词 清除标记
<div class="post-text" itemprop="text"> <p>I have a form, when i click on submit i dont want the page to refresh, thats why i added AJAX to achieve this as you can see. The problem is that its not working. </p> <pre><code> <form id="formFooter" action="" method="post"> <h3>Select your trademark</h3> <select class="form-control" name="trademark"> <option></option> <option>©</option> <option>™</option> <option>®</option> </select> <h3>Your company name</h3> <input class="form-control" type="text" name="companyName" placeholder="Your company name" /> <h3>Background Color</h3> <input class="form-control" placeholder="(e.g. 00ff00)" type="text" name="backgroundColor"> <h3>Font Color</h3> <input class="form-control" placeholder="(e.g. 00ff00)" type="text" name="fontColor"> <h3>Opacity</h3> <input class="form-control" placeholder="(Pick a value between 0 and 1 e.g. 0.3)" type="text" name="opacity"> <br/> <br/> <button class="form-control" id="run" type="submit" name="submit">Generate footer</button> </form> <div id="showData">&nbsp;</div> <script type="text/javascript"> $('#run').on("click", function (e) { var formData = new FormData($('#myForm')[0]); $.ajax({ url: "script.php", type: 'POST', data: formData, success: function (data) { $('#showData').html(data); }, cache: false, contentType: false, processData: false }); return false; }); </script> </code></pre> <p>Here is the script.php:</p> <pre><code><?php function footerPreview () { echo "<h3>Preview:</h3>"; date_default_timezone_set('UTC'); $trademark = $_POST["trademark"]; $company = $_POST["companyName"]; $date = date("Y"); //style $backgroundColor = $_POST['backgroundColor']; $fontColor = $_POST['fontColor']; $opacity = $_POST['opacity']; echo "<div id='generated_footer_date' style='background-color:$backgroundColor; color:$fontColor; opacity: $opacity; ' >$trademark $date $company </div>"; } // generate result for the head function rawHead() { $head = htmlspecialchars('<head> <meta charset="utf-8"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://fonts.googleapis.com/css?family=Raleway:200" rel="stylesheet"> </head>',ENT_QUOTES); echo "<pre><h4>Put this code inside your head tags</h4>$head</pre>"; } // generate result for the body function rawBody () { $body1of5 = htmlspecialchars('<div id="footer_date">',ENT_QUOTES); $body2of5 = $_POST["trademark"]; $body3of5 = date("Y"); $body4of5 = $_POST["companyName"]; $body5of5 = htmlspecialchars('</div>',ENT_QUOTES); echo "<pre><h4>Put this code inside your body tags</h4>$body1of5 $body2of5 $body3of5 $body4of5 $body5of5 </pre>"; } // generate result for the CSS function rawCSS () { $opacity = $_POST['opacity']; $backgroundColor = $_POST['backgroundColor']; $fontColor = $_POST['fontColor']; echo "<pre> <h4>Put this code in your websites stylesheet</h4> color:$fontColor; background-color:$backgroundColor; opacity:$opacity; width:100%; text-align:center; padding-top:15px; height:50px; font-family: 'Raleway', sans-serif; right: 0; bottom: 0; left: 0; position:fixed; </pre>"; } // Generate eveything by one click if(isset($_POST['submit'])) { footerPreview(); rawHead(); rawBody(); rawCSS(); } ?> </code></pre> <p>When i click on submit nothing happens. I want the script.php to be generate on the same page without refreshing. </p> </div>
<div class="post-text" itemprop="text"> <p>Hey I've seen all the solutions here on StackOverflow on the topic but they seem to not work, I don't know why. I've this code inside the <code>$(form).submit(function(e){...});</code> event handler.</p> <p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code> e.preventDefault(); let formData = new FormData(); formData.append('username', username.value); formData.append('password', password.value); $.ajax({ url: 'login.php', type: 'POST', data: formData, processData: false, contentType: false, success: function(response) { console.log(response); }, error: function() { console.log('fail'); } })</code></pre> </div> </div> <p>By the look of things, I think the login.php is receiving the formData value because when I submit the form nothing happens.</p> <p>This is the login.php</p> <p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code><?php session_start(); $password = $username = ''; $_SESSION['user'] = ''; if($_SERVER['REQUEST_METHOD'] == 'POST') { if(isset($_POST['login'])) { include_once('db.php'); $username = strip_tags($_POST['username']); $passd = strip_tags($_POST['password']); $passd = md5($password); $sql = "select * from users where username = '" . $username . "' limit 1"; $query = mysql_query($sql); if($query) { $row = mysql_fetch_assoc($query); $dbpass = $row['password']; if($password == $dbpass) {; $_SESSION['user'] = $username; header('Location: admin.php'); } else { echo 'Wrong username or password!'; } } else { echo mysql_error(); } } } ?></code></pre> </div> </div> <p>How do I make this work? Thank you in advance.</p> </div>
<div class="post-text" itemprop="text"> <p>I don't know why my code does not work onclick, but there is no pop up. The AJAX function var <code>phone</code> and <code>id</code> got data, but the AJAX did not. Is there anything wrong with the script? Does the AJAX need a jQuery library?</p> <pre class="lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/core.js"></script> <script type="text/javascript"> function clickButton() { var phone = document.getElementById('phone').value; var id = document.getElementById('id').value; $.ajax({ type: "post", url: "userDetaiAjax.php", data: { 'phone': phone, 'id': id }, cache: false, success: function(html) { alert('Data Send'); $('#msg').html(html); } }); return false; } </script> <div class="col"> <div class="form-group"> <h6> <label>Name :</label> <?php echo $name ?> </h6> <h6> <label>Email :</label> <?php echo $email ?> </h6> <input type="" name="phone" id="phone"> <input type="" name="id" id="id" value="<?php echo $_SESSION[" staff_id "];?>" hidden> <h6> <label>Phone :</label> <?php echo $phone ?> </h6> <input type="submit" name="aa" value="submit2" onclick="return clickButton();"> </form> <p id="msg"></p> </div> </div> </div> </div> </code></pre> <p>for the url</p> <pre><code><?php $phone = $_POST['phone']; $id = $_POST['id']; echo 'success'; echo $phone; echo $id; $a='"USR_ID"'; $b='"phone"'; include 'conn.php'; if (!$conn) { $e = oci_error(); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $query = "update usr_web SET phone=:c1 WHERE usr_id=:c2"; $stid = oci_parse($conn, $query); oci_bind_by_name($stid, ":c1", $phone); oci_bind_by_name($stid, ":c2", $id); $result = oci_execute($stid); oci_free_statement($stid); oci_commit($conn); oci_close($conn); echo $result; ?> </code></pre> </div>
<div class="post-text" itemprop="text"> <p>I am trying to get this ajax method to work but, for some reason my success function will not execute and I can not retrive informtion from my server. If any one could tell me what I am doing wrong I would apperciate it. My code is below.</p> <pre><code> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="jquery3_2_1.js" type="text/javascript"></script> <script src="Test.js" type="text/javascript"></script> </head> <body> <form class="ajax"> <input type="hidden" name="Item" value="Chicken"> <input type="hidden" name="Price" value="2.99"> <input type="hidden" name="Qty" value="5"> <button type="submit">ADD TO CART</button> </form> <div id="response1"></div> </body> </html> </code></pre> <p>my server code is here:</p> <pre><code><?php //UpdateCart.php echo "This is a test."; ?> </code></pre> <p>here is my jquery:</p> <pre><code>$(document).ready(function(){ $('form.ajax').submit(function(){ alert('Trigger'); $.ajax({ type: "post", url: "UpdateCart.php", dataType: "text", success: function(response){ $('#response1').html('reponse variable equals: '+response); }, error:function(){ $('#response1').html('in error function'); } });//end ajax function });//end submit function });//end ready function </code></pre> <p>When I run the code, the error function is always executed and I never reach the success function block of code. I tried changing the dataType to html but, that does not work. I replaced the submit function with the on function and used the submit parameter and I still can not execute any code in my success function. However, when I remove code that listens to the submit event, I am able to reach my success function. But, I do not want this behaviour from my program. I want to be able to control the request to the server with the submit event. I do not get back any errors from the error function nor do I see anything when I check the network tag in my browser's developer console. I even tried looking into apache's access and error logs but, I do not see any errors or any sign of my code communicating. Any suggestions?</p> <p>p.s. Thanks for all the suggestions. Just to clarify, here are the first things that I tried. I checked the traffic transmitted between the server and my browser and I am not seeing the requested information being returned from my server. I suspect the the ajax method is not sending the request in the first place however, the request is being made. I copied and pasted my uniform request identifier from one code to the next so, I know that it is correct. I took out the action attribute because my application was making the call to the server using the uniform request locator provided by the code in the html and not the url provided by the property in the ajax method. I even went so far as to check apache's access and error logs to see if I could see any http errors that might have been made but, there was no indication of any traffic between my browser and my server. I have tried to use the "event.preventDefault();" but that did not work either. I used the function in the code block that has the submit event listener; I placed it at the end of the code block and it still does not work. I am baffled and do not know what I am doing wrong. </p> </div>
<div class="post-text" itemprop="text"> <p>I wrote a code using jQuery plugin fullcalendar, and everything worked just fine, until I send an $.ajax request in the eventClick.</p> <p>I tried to alert something in the eventClick and it worked, but the ajax request just doesn't work. js code:</p> <pre><code> !function($) { $(document).ready(function() { $("#eventDialog").dialog({ autoOpen : false, modal : true }); var date = new Date(); var d = date.getDay(); var m = date.getMonth(); var y = date.getFullYear(); $("#calendar").fullCalendar({ theme : true, header : { left : 'next,prev today', center : 'title', right : 'month,agendaWeek,agendaDay' }, editable : false, events : [ <?php while ($event = mysql_fetch_array($selectevents)) { $startd = explode(".", $event['start']); $endd = explode(".", $event['end']); $starth = explode(":", $event['starth']); $endh = explode(":", $event['endh']); ?> { id : <?php echo $event['id']; ?>, title : '<?php echo stripslashes($event['title']); ?>', <?php if ($event['allday'] == 1) { ?> start : new Date(<?php echo $startd[2]; ?>,<?php echo $startd[1]-1; ?>,<?php echo $startd[0]; ?>), end : new Date(<?php echo $endd[2]; ?>,<?php echo $endd[1]-1; ?>,<?php echo $endd[0]; ?>) <?php } else { ?> start : new Date(<?php echo $startd[2]; ?>,<?php echo $startd[1]-1; ?>,<?php echo $startd[0]; ?>,<?php echo $starth[0]; ?>,<?php echo $starth[1]; ?>), end : new Date(<?php echo $endd[2]; ?>,<?php echo $endd[1]-1; ?>,<?php echo $endd[0]; ?>,<?php echo $endh[0]; ?>,<?php echo $endh[1]; ?>), allDay : false <?php } ?> } <?php $evNum--; if ($evNum > 0) echo ","; } ?> ], eventClick : function(event) { var eid = event.id; $.ajax({ type : "GET", url : "getEvent.php", data : "id=" + eid, succuss : function(msg) { var title = $("event title", msg).text(); var description = $("event description", msg).text(); var start = $("event start", msg).text(); var end = $("event end", msg).text(); var starth = $("event starth", msg).text(); var endh = $("event endh", msg).text(); $("#eventDialog").attr("title", title); $("#eventDialog #edDescription").html(title); eventDialog.dialog("open"); } }); } }); }); }(jQuery); </code></pre> <p>getEvent.php</p> <pre><code> $id = htmlspecialchars(mysql_real_escape_string($_GET['id'])); $selectevent = mysql_query("SELECT * FROM `calendar` WHERE `id`='$id'") or die(mysql_error()); $event = mysql_fetch_array($selectevent); header("Content-Type: text/xml; charset=utf-8"); echo '<?xml version="1.0" encoding="utf-8" ?>'; echo "<event>"; echo "<id>".$event['id']."</id>"; echo "<title>".stripslashes($event['title'])."</title>"; echo "<description>".$event['description']."</description>"; echo "<start>".$event['start']."</start>"; echo "<end>".$event['end']."</end>"; echo "<starth>".$event['starth']."</starth>"; echo "<endh>".$event['endh']."</endh>"; echo "</event>"; </code></pre> <p>Can anybody point out the problem?</p> <p>Thank's!</p> </div>
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页