Jump to content

Search the Community

Showing results for tags 'ajax'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. I have created the chat system. I want to reload the div so that it can have the effect of instant messaging.I am very new to php. Can anyone help me? Attached is the php file of the display messagees page:( conversations.php
  2. I have adapted a script from w3schools to use as a main menu for my site. It works great in IE, but about 3 or 4 times slower in FireFox, Chrome and Safari! I have no idea what might be wrong and would appreciate any help. Many thanks Mark <html> <head> <script> function showUser(str) { if (str=="") { document.getElementById("hoverbar").innerHTML=""; return; } if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("hoverbar").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","menulookuptest.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <div class='divcolor1' onmouseover='showUser("1")'>Option 1</div> <div class='divcolor2' onmouseover='showUser("2")'>Option 2</div> <div class='divcolor3' onmouseover='showUser("3")'>Option 3</div> <div class='divcolor4' onmouseover='showUser("4")'>Option 4</div> <div class='divcolor5' onmouseover='showUser("5")'>Option 5</div> <div class='divcolor6' onmouseover='showUser("6")'>Option 6</div> <div class='divcolor7' onmouseover='showUser("7")'>Option 7</div> <div class='divcolor8' onmouseover='showUser("8")'>Option 8</div> <div id="hoverbar">Content Goes Here</div> </body> </html> menulookuptest.php <?php $q = $_GET['q']; $con=mysqli_connect("localhost","root","PASS","DBNAME"); mysqli_select_db($con,"ajax_demo"); $sql="SELECT pagetitle, pagedept FROM intranetpage WHERE pagedept = '".$q."'"; $result = mysqli_query($con,$sql); while($row = mysqli_fetch_array($result)) { echo $row['pagetitle']; echo "<BR>"; } ?>
  3. Hi friends, i am new in php, user fill the text box to get the value and post it to the next page using ajax. this is my requirement. i call the textbox in while loop ,so i used the text box name is ship_quantity[] In jquery i get the value like that $('input[name="ship_quantity[]"]').each(function(){ var sq=$(this).val(); alert(sq); now i get the value of 1,2 as user inputs. my questions is how to extract this values and send to ajax post.
  4. Hi guys, I was wondering if i could have some help on a piece of functionality I am trying to implement onto a website I am currently developing. The Scenario is as follows : I have a table residing on a MySql data base called Bookings. The Bookings table consists of a composite primary key based upon the following 2 fields: BookingDate & Booking Slot. On my website, I have built a bookings page which will consist of a a simple HTML Form, which has a Date Field and a Radio-Button group which has 3 different time slots (eg: 9am, 2pm and 4pm). Firstly, the User will select a Date they would wish to place a booking on and then click a submit button called "Check Availablity". Once this button is clicked, Ideally, I would like a script to check an see what free slots are available for that Date and then disable the radio buttons related the slots which are already booked. Here is a simple scenario to help explain the functionality i am trying to implement : The User comes to the Bookings page, and selects the Date 14/03/2011. Then clicks the "Check Availablity" button. In this scenario, the 9am slot is already booked for this date (eg: this booking already exists on the MySql database table), so the 9am radio button on the page is then disabled, not allowing the user to try an attempt to book this timeslot on this date. Below is the a simplified version of the php script which I wrote to implement the this functionality. <?php function checkSlot() { // Get data $test_date = $_GET["bookingDate"]; // Database connection $conn = mysqli_connect("localhost","root","","wordpress"); if(!$conn) { die('Problem in database connection: ' . mysql_error()); } // Attempt to find Duplicate Primary Keys $query = "SELECT Count(*) AS 'total' FROM Bookings WHERE booking_date ='{$booking_date}' AND booking_slot = '9am'"; $result = mysqli_query($conn, $query) or die(mysqli_error($conn)); $num = $result->fetch_assoc(); If ($num['total'] == 0) { echo "<script> document.getElementById('9amTimeSlotRadioButton').disabled = false; </script>"; } else if($num['total'] > 0) { echo "<script> document.getElementById('9amTimeSlotRadioButton').disabled = true; </script>"; } } ?> My problem is that I cant get the Javascript line within the if statement to execute and disable/enable the related 9am radio button. Upon research into this, I have recently found out that it is not possible to do this with just Php and JavaScript, as php runs serverside and javascript runs client-side and Ajax would be needed here. So, im in a spot of bother now as one of the main selling points of this project was to be able to get this functionality working. I have a massive favour to ask of you guys, could you chime in and guide me on how to implement this functionality by using Ajax? I have zero experience in the language so I really dont know where to start. Any input at all on this topic would be much appreciated. Thanks in advance guys, Dave Ireland.
  5. How can I call another script and pass a id so I can fill another drop down pulling data from mysql. I have added the scripts below I just don't understand how to call them $( document ).ready(function() { $.ajax({ //create an ajax request to load_page.php type: "GET", url: "customer.php", dataType: "html", //expect html to be returned success: function(response){ $(".responsetext").html(response); //alert(response); } }); }); THIS SCRIPT FILLES THE DROPDOWE BELOW USING responsetext <select name="customer"id="customer" class="form-control input-sm responsetext"> </select> SO WHEN I SELECT THIS IT WILL PASS THE ID AND RUN THE SCRIPT BELOW $(function() { // document.ready $("#id").on("change", function() { $.ajax({ url: "contact.php", type: "GET", data: { id: $(this).val() }, success: function(data) { $(".contactresults").html(data); } }); }); }); SO IT WILL FILL THIS SELECT BOX WITH contactresults <select name="contact" class="form-control input-sm contactresults" id="contact"> </select>
  6. if(editTblRow==null && editTblCell==null){ if(fieldtype!='blob'){ $($('#ajaxtb')[0].rows[rowid].cells[cellid]).html('<input type="text" id="edit_box" class=\"edit_input\" value=\"' + id + '\" /><div class=\"cell_opts\"><a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','save','','" + updatestring + "');" + '\">Save</a> - <a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','cancel');" + '\">Cancel</a></div>'); } else { $($('#ajaxtb')[0].rows[rowid].cells[cellid]).html('<textarea id="edit_box" class=\"edit_input\" value=\"' + id + '\" >' + id + '</textarea> <div class=\"cell_opts\"><a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','save','','" + updatestring + "');" + '\">Save</a> - <a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','cancel');" + '\">Cancel</a></div>'); } The following code submits data in the input field of an ajax table on the click of the save button but I would like to change it to update on the enter key how can I change the code to do this? Any help would be appreciated. Regards Luke
  7. Hi guys, I am trying to figure out how to pass PHP ID (page.php?id= 'id' ") with ajax request. Getting the ID and storing it into variable called "playlistsongid" <?php session_start(); if(!isset($_GET['id'])) die("No id set"); ?> <?php $playlistsongid = $_GET['id']; ?> function setupyoutubesongarray(firstload) { $.ajax({ 'url': 'post.php', 'async': false, success: function (response) { var posturl="post.php"; // needs to looks something like post.php?id= $.getJSON(posturl,function(data){ youtubesongs = []; $.each(data.members, function(i,song){ result = (song.SongUrl); youtubesongs.push(result); //ytplayer_playlist.push(result); }); loadnextbatchfromsongsarray(); if (firstload = 1) { ytplayer_render_player(); } }); } }); } Any help would be much apreceated!
  8. I have a contact form that gets processes with a Perl script. What I want to do is that when the user fills out the contact form and clicks submit, the reCAPTCHA would get processed and if the user had entered the correct CAPTCHA, it would return true, if not, it would return false and the form would not get processed. Now since the hosting does not allow Perl modules to be installed in order CAPTCHA to be processed there, it must be processed with PHP, that is why I am processing the CAPTCHA with AJAX, behind the scenes. Now, I have done everything, the CAPTCHA gets processed, but hell I can't make it the form not to get submited when the AJAX script returns false. Please help me! Here is the JS script function server_connect(){ // We declare the $connection variable which will hold the // core object depending on the browser. Now we have set it // equal to false since we do not know the user's browser // yet and we haven't defined the variable with the proper // object. var connection = false; // We check whether the browser is any browser but IE 6 - // Since IE 7, that MS browser supports the XMLHttpRequest object. if(window.XMLHttpRequest){ // If the browser supports the object and it doesn't // return 'undefined' make a new instance of the object and // assign it to the $connection variable. // If not, set $connection to false which means // this browser doesn't support the XMLHttpObject // and that means the user has IE version below 7. if(typeof XMLHttpRequest != "undefined"){ try{ connection = new XMLHttpRequest(); }catch(e){ connection = false; } } // If the above evaluation fails, // we make a new evaluation to set $connection with the // right object, in this case, for IE 6 - }else if(window.ActiveXObject){ try{ connection = new ActiveXObject('Microsoft.XMLHTTP'); }catch(e){ try{ connection = new ActiveXObject('Msxml2.XMLHTTP'); }catch(e){ connection = false; } } } // The return value of this function is // either the right AJAX server connection object // or false which means that AJAX cannot connect for some reason. return connection; } // We set the object to a variable and now we can use its properties // and methods when connecting to the server behind the scenes. var connection = server_connect(); // It's easy :-) // /****************************************************************************/ window.onload = function(){ var submit_button = document.getElementById('submit_button'); var cform = document.getElementById('cform'); cform.onsubmit = function(){ var response_text = document.ZIPTIE.recaptcha_response_field.value; var challenge_text = document.ZIPTIE.recaptcha_challenge_field.value; if(connection){ connection.onreadystatechange = function(){ if(connection.readyState == 4 && connection.status == 200){ if(connection.responseText == 10){ alert('OK'); return true; // Should return true if the responseText from verify.php is '10' }else{ alert(false); return false; // Should return false if the responseText from verify.php is not 10 } } } // before connection.open("GET","verify.php?c="+challenge_text+"&r="+response_text,true); connection.send(); } return false; } } And the HTML: <form action="process.pl" method="post" name="ZIPTIE" id="cform"> <br /> <table width="800" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><strong><font size="+2">Please tell us what you think!</font></strong></td> </tr> </table> <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" > <BR> <TR> <td width="230" valign="middle"><STRONG>Your Name:</STRONG></TD> <td valign="middle"><INPUT NAME="name" SIZE="40" MAXLENGTH="100"></TD> </TR> <TR> <td valign="middle"><STRONG>Phone Number:</STRONG></TD> <td valign="middle"><INPUT NAME="phone_number" SIZE="40" MAXLENGTH="100"></TD> </TR> <TR> <td valign="middle"><STRONG>E-mail Address:</STRONG></TD> <td valign="middle"><INPUT NAME="email_address" SIZE="40" MAXLENGTH="100"></TD> </TR> <TR> <td valign="middle"><img src="images/spacer.png" width="1" height="8" border="0" /></TD> <td valign="middle"></TD> </TR> <TD WIDTH="230"><STRONG>Type of Feedback:</STRONG></TD> <TD> <SELECT NAME="type"> <OPTION VALUE="Positive">Positive</OPTION> <OPTION VALUE="Complaint">Complaint</OPTION> <OPTION VALUE="Comment">Comment</OPTION> <OPTION VALUE="Request">Request</OPTION> </SELECT> </TD> </tr> <TR> <td valign="middle"><img src="images/spacer.png" width="1" height="8" /></TD> <td valign="middle"></TD> </TR> <tr> <TD WIDTH="230"><STRONG>Store Location Your Writing About:</STRONG></TD> <TD> <SELECT NAME="location"> <OPTION VALUE="Portland">Portland</OPTION> <OPTION VALUE="Grand Ledge">Grand Ledge</OPTION> <OPTION VALUE="St. Louis">St. Louis</OPTION> <OPTION VALUE="Linwood">Linwood</OPTION> <OPTION VALUE="Rosebush">Rosebush</OPTION> <OPTION VALUE="Tecumseh">Tecumseh</OPTION> <OPTION VALUE="South Lyon">South Lyon</OPTION> </SELECT> </TD> </tr> <TR> <td valign="middle"><img src="images/spacer.png" width="1" height="12" /></TD> <td valign="middle"></TD> </TR> <TR> <td valign="middle">Your Message:</TD> <td valign="middle"><textarea name="message" cols="65" rows="4"></textarea></TD> </TR> <TR> <td valign="middle"><img src="images/spacer.png" width="1" height="8" /></TD> <td valign="middle"></TD> </TR> <TR> <td valign="middle"><img src="images/spacer.png" width="5" height="8" />Human Verification:</TD> <td valign="middle"> CAPTCHA!!!! <script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=6Leh-OYSAAAAAHvM0Ty2b6CsHilEgu4mM8oEsdvG "> </script> <noscript> <iframe src="http://www.google.com/recaptcha/api/noscript?k=6Leh-OYSAAAAAHvM0Ty2b6CsHilEgu4mM8oEsdvG " height="300" width="500" frameborder="0"></iframe><br> <textarea name="recaptcha_challenge_field" rows="3" cols="40" id="challenge"></textarea> <input type="hidden" name="recaptcha_response_field" value="manual_challenge" id="response"> </noscript> END OF CAPTCHA!!! </TD> </TR> </table> <br /> <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000"> <TR> <td align="center"> <FONT COLOR="#fff707"><strong>IMPORTANT!</strong> - We will not use your personal information in any manner other than you have approved!</FONT> </TD> </TR> </TABLE> <br /> <table align="center"> <TR> <TD> <INPUT TYPE="SUBMIT" VALUE="Submit" id="submit_button"> <INPUT TYPE="RESET" VALUE="Clear Form"></FORM></TD> I didn't write the HTML form, it was written by someone else. And I am not using jQuery because it is lame.
  9. When I hard code the URL variable of this AJAX call, all is well, it executes and returns expected values. But when I replace part of the URL variable with a PHP variable, the AJAX fails to execute. There are no errors or flags being thrown by javaconsole or PHP. When i look at source view of page in either circumstance, they are identical - the PHP variable has been replaced properly. Why might the use of the PHP echo break the AJAX execution even though when viewing the source all appears to be normal? Hard coded version: <?php $domain="http://www.somewebsite.com/"; ?> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { if( $("#dig6").val() ) { $.ajax({ type : 'POST', url : 'http://www.somewebsite.com/includes/ffl2.php', data: { var1 : $('#dig1').val(), var2 : $('#dig2').val(), var3 : $('#dig6').val(), fflck : "chk" }, success:function (data) { $("#datatarget").append(data); } }); } }); </script> Version using PHP variable: <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { if( $("#dig6").val() ) { $.ajax({ type : 'POST', url : '<?php echo $domain; ?>includes/ffl2.php', data: { var1 : $('#dig1').val(), var2 : $('#dig2').val(), var3 : $('#dig6').val(), fflck : "chk" }, success:function (data) { $("#datatarget").append(data); } }); } }); </script> Snippet of 'view source' after page ready with PHP variable in AJAX call: <-- MORE CODE HERE --> $.ajax({ type : 'POST', url : 'http://www.somewebsite.com/includes/ffl2.php', data: { var1 : $('#dig1').val(), var2 : $('#dig2').val(), var3 : $('#dig6').val(), fflck : "chk" <-- MORE CODE HERE -->
  10. Hello, so I am a new member here and I would need some help. I could'nt decide if I post my problem to ajax or javascript topic . I have bought dating site software called eMeeting. I tried to add a custom javascript slider to the header. The slider needs jquery library to work, but when I import the library, other scripts from the webpage stop working. So here is a quick demo. This is my sites header. When I click to "SMS Kuulutused" link (marked with red circle) this appears: So the problem is now when I click to the status box on the same page nothing happens. But if I comment the line below (located in sliders js file) <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> Other javascripts from the page will work again and the result for this demo when clicked the red circle would be this: It would be really nice if someone has some time to help me or give me some suggestions. Also the webpage is http://flirt.ee Best Regards, Mairo
  11. I am using the following code from a third party script which I purchased. At the moment there is a "save" button which submits what is in the text field of an ajax table. I am wanting to change it to on enter submit the data. How can I modify the following code to do so. //Declare Some Global Variables var cancelString; var editTblRow; var editTblCell; var editSQLRowID; var editKey; var editCancel; function showDelete(id) { $("#del_" + id).toggle(); } function loadTable(){ $("#ajaxTable").load("table.php"); } function insertRow(){ $("#ajaxTable").load("dbFunc.php?action=new"); } function selectTable(optvalue){ editTblRow = null; editTblCell = null; $("#active_table").val(optvalue); $("#ajaxTable").load("table.php?table=" + optvalue); } function loadingTimer(){ $("#ajax_loading_div") .bind("ajaxSend", function(){ $(this).show(); }) .bind("ajaxComplete", function(){ $(this).hide(); }); } function delRow(thisRow,rowID){ var delConfirm = confirm("Delete this row?"); if (delConfirm){ $.get("dbFunc.php", { action: 'delete', rowid: rowID }, function(data){ $(thisRow).parent().fadeOut(500, function() {$(thisRow).remove(); }); }); } } function cancelInsert(rowID){ $.get("dbFunc.php", { action: 'delete', rowid: rowID }, function(data){ loadTable(); }); } function toggleDelRow(rowid){ $("#"+rowid).toggle(); } function searchTable(searchTerm){ loadingTimer(); $("#ajaxTable").load("table.php?search=" + encodeURI(searchTerm) + "&table=" + $('#active_table').val()); } function gotoStart(start){ loadingTimer(); var search_text = ''; if($("#searchText").val()!='Search'){search_text=$("#searchText").val()} $("#ajaxTable").load("table.php?start=" + start + "&search=" + search_text + "&table=" + $('#active_table').val()); } function sortTable(order_by,direction){ loadingTimer(); var search_text = ''; if($("#searchText").val()!='Search'){search_text=$("#searchText").val()} $("#ajaxTable").load("table.php?start=0&search=" + search_text + "&order_by=" + order_by + "&direction=" + direction + "&table=" + $('#active_table').val()); $("#" + order_by).attr("src","img' + '../img/ajax/arrow_down.gif"); } this.label2value = function(){ var inactive = "inactive"; var active = "active"; var focused = "focused"; $("label").each(function(){ obj = document.getElementById($(this).attr("for")); if($(this).attr("for")=="searchText"){ if(($(obj).attr("type") == "text") || (obj.tagName.toLowerCase() == "textarea")){ $(obj).addClass(inactive); var text = $(this).text(); $(this).css("display","none"); $(obj).val(text); $(obj).focus(function(){ $(this).addClass(focused); $(this).removeClass(inactive); $(this).removeClass(active); if($(this).val() == text) $(this).val(""); }); $(obj).blur(function(){ $(this).removeClass(focused); if($(this).val() == "") { $(this).val(text); $(this).addClass(inactive); } else { $(this).addClass(active); }; }); }; }; }); }; var t = document.getElementsByTagName("tr"); for(var i=0;i<t.length;i++) { var ocn = t[i].className; t[i].onmouseover = function() { t[i].className = "hovered" }; t[i].onmouseout = function() { t[i].className = ocn }; } function editCell(rowid,cellid,sqlrowid,key,id,type,fieldtype,updatestring) { if(type=='cancel'){ $($('#ajaxtb')[0].rows[editTblRow].cells[editTblCell]).hide().html(cancelString).fadeIn('slow'); $($('#ajaxtb')[0].rows[editTblRow].cells[editTblCell]).removeClass('tdHover'); showDelete(editTblRow-1); editCancel=true; } else if(type=='save'){ $.ajax({ url: 'database.php', type: 'GET', data: "text=" + $('#edit_box').val() + "&sqlrowid=" + editSQLRowID + "&field=" + editKey + "&table=" + $('#active_table').val() + "&updatestring=" + escape(updatestring), success: function(response){ if(updatestring){$("#ajaxTable").load("table.php");} else { $($('#ajaxtb')[0].rows[editTblRow].cells[editTblCell]).html(response); } editTblRow = null; editTblCell = null; } }); $($('#ajaxtb')[0].rows[editTblRow].cells[editTblCell]).removeClass('tdHover'); showDelete(editTblRow-1); } else { if(editTblRow==null && editTblCell==null){ if(fieldtype!='blob'){ $($('#ajaxtb')[0].rows[rowid].cells[cellid]).html('<input type="text" id="edit_box" class=\"edit_input\" value=\"' + id + '\" /><div class=\"cell_opts\"><a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','save','','" + updatestring + "');" + '\">Save</a> - <a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','cancel');" + '\">Cancel</a></div>'); } else { $($('#ajaxtb')[0].rows[rowid].cells[cellid]).html('<textarea id="edit_box" class=\"edit_input\" value=\"' + id + '\" >' + id + '</textarea> <div class=\"cell_opts\"><a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','save','','" + updatestring + "');" + '\">Save</a> - <a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','cancel');" + '\">Cancel</a></div>'); } editTblRow = rowid; editTblCell = cellid; editSQLRowID = sqlrowid; editKey = key; cancelString = id; } else { if(editTblRow==rowid && editTblCell==cellid){ //We are currently editing this cell. Do nothing if clicked. if(editCancel==true){ editTblRow = null; editTblCell = null; } editCancel=false; return false; } else { //Load a new edit box on a new cell $($('#ajaxtb')[0].rows[editTblRow].cells[editTblCell]).hide().html(cancelString).fadeIn('slow'); if(fieldtype!='blob'){ $($('#ajaxtb')[0].rows[rowid].cells[cellid]).html('<input type="text" id="edit_box" class=\"edit_input\" value=\"' + id + '\" /> <div class=\"cell_opts\"><a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','save','','" + updatestring + "');" + '\">Save</a> - <a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','cancel');" + '\">Cancel</a></div>'); } else { $($('#ajaxtb')[0].rows[rowid].cells[cellid]).html('<textarea id="edit_box" class=\"edit_input\" value=\"' + id + '\" >' + id + '</textarea> <div class=\"cell_opts\"><a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','save','','" + updatestring + "');" + '\">Save</a> - <a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','cancel');" + '\">Cancel</a></div>'); } editTblRow = rowid; editTblCell = cellid; editSQLRowID = sqlrowid; editKey = key; cancelString = id; } } } }
  12. I read a basic ajax tutorial and could get it to work more or less. all the files that the ajax loads are .html files. The Ajax index file is also a .html file. Will it be possible to load php files with ajax ? And is is also possible to have a index.php file instead of the current index.html file ? I would like to have a login page and after logging in the site should track the session The login page will have to display a message if the user is already logged in or made a mistake in logging in (bad username / password combination) The login page would be the only php page that has to be loaded. If having to load 2 different types of pages (html and php) is not possible are there any drawbacks at renaming all the html files into php files ? thank you
  13. I'm wondering the best way to handle validation messages for blind people, or sight-impaired. In my application, the situation on a save with errors is: User clicks save AJAX call goes to save the record; wait bar appears on the page's status bar Error is returned. The wait bar changes to show "Error on save" Below the status bar, each field name is listed with the appropriate error message. ("Name - Cannot be blank" or whatever) Within the fields themselves, the same message is shown again. (Next to the "Name" label on the page, "cannot be blank" would show up.) This functionality is great for sighted people. But for non-sighted, I'm not sure exactly how to handle it. Should an error become "selected" or something? I mean, it's just a div. I don't really have the answer. I posted this in general HTML but it could frankly be AJAX or JS or something. I think HTML is probably the most correct.
  14. I bought the following script http://www.sevenscript.net/ajax-powered-mysql-table-editor/. It is a ajax table editor with in-line editing It comes with the following files. ajaxtable.js /*Sevenscript <http://sevenscript.net> - Copyright (c) 2010 <info@sevenscript.net>*/ //Declare Some Global Variables var cancelString; var editTblRow; var editTblCell; var editSQLRowID; var editKey; var editCancel; function showDelete(id) { $("#del_" + id).toggle(); } function loadTable(){ $("#ajaxTable").load("table.php"); } function insertRow(){ $("#ajaxTable").load("dbFunc.php?action=new"); } function selectTable(optvalue){ editTblRow = null; editTblCell = null; $("#active_table").val(optvalue); $("#ajaxTable").load("table.php?table=" + optvalue); } function loadingTimer(){ $("#ajax_loading_div") .bind("ajaxSend", function(){ $(this).show(); }) .bind("ajaxComplete", function(){ $(this).hide(); }); } function delRow(thisRow,rowID){ var delConfirm = confirm("Delete this row?"); if (delConfirm){ $.get("dbFunc.php", { action: 'delete', rowid: rowID }, function(data){ $(thisRow).parent().fadeOut(500, function() {$(thisRow).remove(); }); }); } } function cancelInsert(rowID){ $.get("dbFunc.php", { action: 'delete', rowid: rowID }, function(data){ loadTable(); }); } function toggleDelRow(rowid){ $("#"+rowid).toggle(); } function searchTable(searchTerm){ loadingTimer(); $("#ajaxTable").load("table.php?search=" + encodeURI(searchTerm) + "&table=" + $('#active_table').val()); } function gotoStart(start){ loadingTimer(); var search_text = ''; if($("#searchText").val()!='Search'){search_text=$("#searchText").val()} $("#ajaxTable").load("table.php?start=" + start + "&search=" + search_text + "&table=" + $('#active_table').val()); } function sortTable(order_by,direction){ loadingTimer(); var search_text = ''; if($("#searchText").val()!='Search'){search_text=$("#searchText").val()} $("#ajaxTable").load("table.php?start=0&search=" + search_text + "&order_by=" + order_by + "&direction=" + direction + "&table=" + $('#active_table').val()); $("#" + order_by).attr("src","img' + '../img/ajax/arrow_down.gif"); } this.label2value = function(){ var inactive = "inactive"; var active = "active"; var focused = "focused"; $("label").each(function(){ obj = document.getElementById($(this).attr("for")); if($(this).attr("for")=="searchText"){ if(($(obj).attr("type") == "text") || (obj.tagName.toLowerCase() == "textarea")){ $(obj).addClass(inactive); var text = $(this).text(); $(this).css("display","none"); $(obj).val(text); $(obj).focus(function(){ $(this).addClass(focused); $(this).removeClass(inactive); $(this).removeClass(active); if($(this).val() == text) $(this).val(""); }); $(obj).blur(function(){ $(this).removeClass(focused); if($(this).val() == "") { $(this).val(text); $(this).addClass(inactive); } else { $(this).addClass(active); }; }); }; }; }); }; var t = document.getElementsByTagName("tr"); for(var i=0;i<t.length;i++) { var ocn = t[i].className; t[i].onmouseover = function() { t[i].className = "hovered" }; t[i].onmouseout = function() { t[i].className = ocn }; } function editCell(rowid,cellid,sqlrowid,key,id,type,fieldtype,updatestring) { if(type=='cancel'){ $($('#ajaxtb')[0].rows[editTblRow].cells[editTblCell]).hide().html(cancelString).fadeIn('slow'); $($('#ajaxtb')[0].rows[editTblRow].cells[editTblCell]).removeClass('tdHover'); showDelete(editTblRow-1); editCancel=true; } else if(type=='save'){ $.ajax({ url: 'database.php', type: 'GET', data: "text=" + $('#edit_box').val() + "&sqlrowid=" + editSQLRowID + "&field=" + editKey + "&table=" + $('#active_table').val() + "&updatestring=" + escape(updatestring), success: function(response){ if(updatestring){$("#ajaxTable").load("table.php");} else { $($('#ajaxtb')[0].rows[editTblRow].cells[editTblCell]).html(response); } editTblRow = null; editTblCell = null; } }); $($('#ajaxtb')[0].rows[editTblRow].cells[editTblCell]).removeClass('tdHover'); showDelete(editTblRow-1); } else { if(editTblRow==null && editTblCell==null){ if(fieldtype!='blob'){ $($('#ajaxtb')[0].rows[rowid].cells[cellid]).html('<input type="text" id="edit_box" class=\"edit_input\" value=\"' + id + '\" /> <div class=\"cell_opts\"><a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','save','','" + updatestring + "');" + '\">Save</a> - <a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','cancel');" + '\">Cancel</a></div>'); } else { $($('#ajaxtb')[0].rows[rowid].cells[cellid]).html('<textarea id="edit_box" class=\"edit_input\" value=\"' + id + '\" >' + id + '</textarea> <div class=\"cell_opts\"><a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','save','','" + updatestring + "');" + '\">Save</a> - <a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','cancel');" + '\">Cancel</a></div>'); } editTblRow = rowid; editTblCell = cellid; editSQLRowID = sqlrowid; editKey = key; cancelString = id; } else { if(editTblRow==rowid && editTblCell==cellid){ //We are currently editing this cell. Do nothing if clicked. if(editCancel==true){ editTblRow = null; editTblCell = null; } editCancel=false; return false; } else { //Load a new edit box on a new cell $($('#ajaxtb')[0].rows[editTblRow].cells[editTblCell]).hide().html(cancelString).fadeIn('slow'); if(fieldtype!='blob'){ $($('#ajaxtb')[0].rows[rowid].cells[cellid]).html('<input type="text" id="edit_box" class=\"edit_input\" value=\"' + id + '\" /> <div class=\"cell_opts\"><a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','save','','" + updatestring + "');" + '\">Save</a> - <a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','cancel');" + '\">Cancel</a></div>'); } else { $($('#ajaxtb')[0].rows[rowid].cells[cellid]).html('<textarea id="edit_box" class=\"edit_input\" value=\"' + id + '\" >' + id + '</textarea> <div class=\"cell_opts\"><a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','save','','" + updatestring + "');" + '\">Save</a> - <a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','cancel');" + '\">Cancel</a></div>'); } editTblRow = rowid; editTblCell = cellid; editSQLRowID = sqlrowid; editKey = key; cancelString = id; } } } } DATABASE.PHP <?php /*Sevenscript <http://sevenscript.net> - Copyright (c) 2010 <info@sevenscript.net>*/ require_once('config.php'); $update_text = $_GET['text']; $sqlrowid = $_GET['sqlrowid']; $field = $_GET['field']; $updatestring = $_GET['updatestring']; if($updatestring){ $result = @mysql_query("SHOW COLUMNS FROM $table"); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $field_list .= $row['Field'] . ","; } $field_list = substr($field_list,0,-1); } $sql = "UPDATE $table SET $field= '$update_text' WHERE CONCAT_WS('',$field_list) = '$updatestring' LIMIT 1"; if(mysql_query ( $sql )){ echo $update_text; } } $sql = "UPDATE $table SET $field= '$update_text' WHERE _rowid = '$sqlrowid'"; if(mysql_query ( $sql )){ echo $update_text; } ?> DBFUNC.PHP <?php Header('Cache-Control: no-cache'); //IE Fix /*Sevenscript <http://sevenscript.net> - Copyright (c) 2010 <info@sevenscript.net>*/ require_once('config.php'); $action = $_GET['action']; $rowid = $_GET['rowid']; if($action=="delete"){ $sql = "DELETE FROM $table WHERE _rowid='$rowid' LIMIT 1"; mysql_query ( $sql ); } if($action=="new"){ //Insert a new row into the database mysql_query("INSERT INTO $table VALUES()"); $new_row = mysql_insert_id(); if(!$fields){ $result = @mysql_query("SHOW COLUMNS FROM $table"); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $fields[$row['Field']] = $row['Field']; $field_list .= $row['Field'] . ","; } $field_list = substr($field_list,0,-1); } } ?> <div class="tableBorder"> <table class="ajaxTable" cellpadding="0" cellspacing="0" border="0" id="ajaxtb"> <thead> <tr> <?php foreach($fields as $key => $val){ if($key == $get_order_by){ $imgsrc = "img/ajax/$direction.gif"; $sort = $direction; } else { $imgsrc = "img/ajax/arrows_updown.gif"; $sort = "DESC"; } echo "<th width=\"$width[$val]\">$val</th>"; } ?> <th> </th></tr> </thead> <tbody> <?php $sql = "SELECT count(*) AS num FROM $table $search_sql $order_by LIMIT $pageLimit"; $result = mysql_query ( $sql ); $rowCount = mysql_result($result,0,"num"); foreach($fields as $key => $val){ $select_fields .= $key . ","; } $select_fields = substr($select_fields,0,-1); $sql = "SELECT _rowid as rowid,$select_fields FROM $table $search_sql $order_by WHERE _rowid=$new_row LIMIT 1"; $row = mysql_query ( $sql ); while ( $result = mysql_fetch_array ( $row ) ) { echo "<tr class=\"tdOdd\" onmouseout=\"showDelete('$x');\" onmouseover=\"showDelete('$x');\">"; $fieldval=1; while($fieldval <= sizeof($fields)){ $fieldtype[$fieldval] = @mysql_field_type($row,$fieldval); $fieldval++; } $fieldpos=1; foreach($fields as $key => $val){ $filteredKey = htmlspecialchars(addslashes($result[$key])); echo "<td class=\"edit_cell\" style=\"$style[$key]\" id=\"$result[$key]\" onmouseover=\"$(this).addClass('tdHover');\" onmouseout=\"$(this).removeClass('tdHover');\" onclick=\"editCell(this.parentNode.rowIndex,this.cellIndex,'$result[rowid]','$key',this.innerHTML,'','$fieldtype[$fieldpos]','$result[updatestring]');\">" . $result[$key] . "</td>"; $fieldpos++; } ?> <td style="width: 28px; height: 28px;" onclick="delRow(this,'<?php echo $result['rowid']; ?>');"><div id="del_<?php echo $x; ?>" style="display: none;"><img src="img/ajax/delete_icon.gif" /></div></td></tr> <?php $x++; } ?> </tbody> <tfoot> <tr><td colspan="30"><input type="button" value="Done" onclick="loadTable();" /><input type="button" value="Cancel" onclick="cancelInsert('<?php echo $new_row; ?>');" /></td></tr> </tfoot> </table> <?php } ?> TABLE.PHP <?php Header('Cache-Control: no-cache'); //IE Fix //Sevenscript <http://sevenscript.net> - Copyright (c) 2009 Stuart Rutter <contact@sevenscript.net> require_once('config.php'); if(isset($_GET['table'])){ //$table = $_GET['table']; } if(!$fields){ $result = @mysql_query("SHOW COLUMNS FROM $table"); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $fields[$row['Field']] = $row['Field']; $field_list .= $row['Field'] . ","; } $field_list = substr($field_list,0,-1); } } $get_search = mysql_real_escape_string($_GET['search']); $get_start = mysql_real_escape_string($_GET['start']); $get_direction = mysql_real_escape_string($_GET['direction']); $get_order_by = mysql_real_escape_string($_GET['order_by']); if($get_search){ if(!$searchField){ $search_sql = " WHERE "; foreach($fields as $key=>$val){ $search_sql .= "$key LIKE '%$get_search%' OR "; } $search_sql = substr($search_sql,0,-4); } else { $search_sql = " WHERE $searchField LIKE '%$get_search%' "; } } if($get_start){ $start = $get_start; } else { $start = "0"; } if($get_direction){ $direction = $get_direction; } if($direction=="ASC"){$direction="DESC";} else { $direction="ASC";} if($get_order_by){ $order_by = " ORDER BY $get_order_by " . $direction; } else { $order_by = " "; } if($sortField && !$get_order_by){ $get_order_by = $sortField; $direction = $sortOrder; $order_by = " ORDER BY $get_order_by " . $direction; } ?> <div class="tableBorder"> <table class="ajaxTable" cellpadding="0" cellspacing="0" border="0" id="ajaxtb"> <thead> <tr> <?php foreach($fields as $key => $val){ if($key == $get_order_by){ $imgsrc = "img/ajax/$direction.gif"; $sort = $direction; } else { $imgsrc = "img/ajax/arrows_updown.gif"; $sort = "DESC"; } echo "<th width=\"$width[$val]\"><a href=\"#\" onclick=\"javascript:sortTable('$key','$sort');\">$val<img id=\"$key\" src=\"$imgsrc\" /></a></th>"; } ?> <th> </th></tr> </thead> <tbody> <?php $sql = "SELECT count(*) AS num FROM $table $search_sql $order_by LIMIT $pageLimit"; $result = mysql_query ( $sql ); $rowCount = mysql_result($result,0,"num"); foreach($fields as $key => $val){ $select_fields .= $key . ","; } $select_fields = substr($select_fields,0,-1); //Check if there is a primary key on the table $sql = "SELECT _rowid FROM $table"; $row= mysql_query ($sql); if(!$row){ $sql = "SELECT CONCAT_WS('',$field_list) as updatestring,$select_fields FROM $table $search_sql $order_by LIMIT $start, $pageLimit"; } else { $sql = "SELECT _rowid as rowid,$select_fields FROM $table $search_sql $order_by LIMIT $start, $pageLimit"; } $row = mysql_query ( $sql ); while ( $result = mysql_fetch_array ( $row ) ) { if ( $x&1 ){ echo "<tr class=\"tdOdd\" onmouseover=\"showDelete('$x');\" onmouseout=\"showDelete('$x');\">"; } else { echo "<tr class=\"tdEven\" onmouseout=\"showDelete('$x');\" onmouseover=\"showDelete('$x');\">"; } $fieldval=1; while($fieldval <= sizeof($fields)){ $fieldtype[$fieldval] = @mysql_field_type($row,$fieldval); $fieldval++; } $fieldpos=1; foreach($fields as $key => $val){ $filteredKey = htmlspecialchars(addslashes($result[$key])); echo "<td class=\"edit_cell\" style=\"$style[$key]\" id=\"$result[$key]\" onmouseover=\"$(this).addClass('tdHover');\" onmouseout=\"$(this).removeClass('tdHover');\" onclick=\"editCell(this.parentNode.rowIndex,this.cellIndex,'$result[rowid]','$key',this.innerHTML,'','$fieldtype[$fieldpos]','$result[updatestring]');\">" . $result[$key] . "</td>"; $fieldpos++; } ?> <td style="width: 28px; height: 28px;" onclick="delRow(this,'<?php echo $result['rowid']; ?>');"><div id="del_<?php echo $x; ?>" style="display: none;"><img src="img/ajax/delete_icon.gif" /></div></td></tr> <?php $x++; } $numberOfPages = ceil($rowCount / $pageLimit); ?> </tbody> <tfoot> <tr><td colspan="30"><h2><?php echo $rowCount . " Results - " . $numberOfPages . " Pages"; ?></h2></td></tr> </tfoot> </table> </div> <div class="pagination"> <?php $current_page = ceil($start / $pageLimit) + 1; $x=1; $start=0; if($current_page<=9){ while($x<=$numberOfPages){ if($x<=10){ if($current_page == $x){$class="paginationSelected";} else { $class="paginationNotSelected";} echo "<a href=\"javascript: void(0)\" class=\"$class\" onclick=\"javascript:gotoStart($start);\">$x</a> "; } if($x>10 && $x == $numberOfPages){ echo " ... <a href=\"javascript: void(0)\" class=\"$class\" onclick=\"javascript:gotoStart($start);\">$x</a> "; } $start = $start + $pageLimit; $x++; } } $x=1; if($current_page>=10){ $pageCounter = $current_page - 5; while($x<=10){ $pageNumber = $pageCounter * $pageLimit - $pageLimit; if($pageCounter<=$numberOfPages){ if($current_page == $pageCounter){$class="paginationSelected";} else { $class="paginationNotSelected";} echo "<a href=\"javascript: void(0);\" class=\"$class\" onclick=\"javascript:gotoStart($pageNumber);\">$pageCounter</a> "; } $pageCounter++; $x++; } } ?> <div class="newRowBtn"><input type="image" onclick="insertRow();" src="img/ajax/new_row_btn.png" value="Insert New Row" /></div> </div> <!-- <div class="tableBorder"> <table class="ajaxTable" cellpadding="0" cellspacing="0" border="0" id="ajaxtb"> <thead> <tr> <th></th> </tr> </thead> <tbody> <tr><td class="tdOdd"><div class="table_msg">Not Connected. Please use the login form.</div></td></tr> </tbody> </table> </div> --> And then my file process.php <?php include('core/config.php'); include ('includes/header.php'); if(!isset($_SESSION['user'])) { header('Location: ' . $url . '/login.php'); die(); } <div id="container"> <?php $con=mysqli_connect("localhost","user","pass!","db"); if(mysqli_errno($con)) { echo "Can't Connect to mySQL:".mysqli_connect_error(); } $fetch="SELECT ".$_SESSION['user']."_temp_table_1.UFP_CODE FROM ".$_SESSION['user']."_temp_table_1 LEFT OUTER JOIN InvManCen ON ".$_SESSION['user']."_temp_table_1.UFP_CODE = InvManCen.UFPCODE WHERE InvManCen.BLOCK = '2'"; $result = mysqli_query($con,$fetch); if(!$result) { echo "Error:".(mysqli_error($con)); } echo '<table class="center" align=center>'//.'<tr>'.'<td align="center">'. 'From Database'. '</td>'.'</tr>' ; echo '<tr>'.'<td>'.'<table>'.'<tr>'.'<td align=center>'.'Important Information'.'</td>'.'</tr>'; while($data=mysqli_fetch_row($result)) { echo ("<tr><td align=center><div class='alert-box notice'>Product with UFP Code $data[0] Is Blocked</div></td></tr>"); } echo '</table>'.'</td>'.'</tr>'.'</table>'; //<td>$data[2]</td><td>$data[3]</td><td>$data[4]</td> ?> <div class="ajaxTableHeader"></span> <label for="searchText">Search</label> <input type="text" id="searchText" class="tableSearch_input" name="searchText" value="" size="30" onkeyup="javascript:searchTable(this.value);" /> <div id="ajax_loading_div" style="display:none;"><img src="img/ajax/ajax-loader.gif" alt="Loading" /></div> </div> </br></br> <div id="ajaxTable"></div> </div> <button onclick="window.location.href='process3.php?&start=0&s=&f=&sort=id&ad=a'">Generate Quote</button> <button onclick="window.location.href='refresh.php'">Refresh</button> <?php include ('includes/footer.php'); ?> Is there any way we can make it so only one specific column is editable as at the moment all the values are editable.. when updating a column is there any way we can press enter rather than pressing the save button? Is it possible to get data from two tables. Like using a LEFT OUTER JOIN in mysql. Can someone help with this?
  15. How to filter and show data in search without using submit button..because thats the only function i need to finish my code..can anyone help me? I dont want to use submit button cause it refreshes the page...I have the code for search already I need a function that after I search the data will show in the textboxes without using submit button. php code: <?php if($_GET){ include('include/connect.php'); $batchcode = $_GET['code']; $sql = mysql_query("SELECT aic,batchcode,address,name FROM tb_app WHERE batchcode = '".$batchcode."' "); if($sql) { while($rows = mysql_fetch_array($sql)){ $aic[] = $rows['aic']; $name[] = $rows['name']; $address[] = $rows['address']; } } }else{ $aic = array(NULL,NULL,NULL,NULL); $name = array(NULL,NULL,NULL,NULL); $address = array(NULL,NULL,NULL,NULL); } ?> html code: <html> <head> <title>test</title> </head> <body> <form action="" method="get"> Search Batchcode:<input type="text" name="code" id="query" /><br /> <table> <tr> <td> aic: <br /> <input type="text" name="optA1" value="<?php if(empty($aic[0])){$aic[0] = array(NULL);}else{echo $aic[0];} ?>" /> <br /> <input type="text" name="optA2" value="<?php if(empty($aic[1])){$aic[1] = array(NULL);}else{echo $aic[1];} ?>" /> <br /> <input type="text" name="optA3" value="<?php if(empty($aic[2])){$aic[2] = array(NULL);}else{echo $aic[2];} ?>" /> <br /> <input type="text" name="optA4" value="<?php if(empty($aic[3])){$aic[3] = array(NULL);}else{echo $aic[3];} ?>" /> <br /> </td> <td> Name List: <br /> <input type="text" name="optB1" value="<?php if(empty($name[0])){$name[0] = array(NULL);}else{echo $name[0];} ?>" /> <br /> <input type="text" name="optB2" value="<?php if(empty($name[1])){$name[1] = array(NULL);}else{echo $name[1];} ?>" /> <br /> <input type="text" name="optB3" value="<?php if(empty($name[2])){$name[2] = array(NULL);}else{echo $name[2];} ?>" /> <br /> <input type="text" name="optB4" value="<?php if(empty($name[3])){$name[3] = array(NULL);}else{echo $name[3];} ?>" /> <br /> </td> <td> Address: <br /> <input type="text" name="optC1" value="<?php if(empty($address[0])){$address[0] = array(NULL);}else{echo $address[0];} ?>" /> <br /> <input type="text" name="optC2" value="<?php if(empty($address[1])){$address[1] = array(NULL);}else{echo $address[1];} ?>" /> <br /> <input type="text" name="optC3" value="<?php if(empty($address[2])){$address[2] = array(NULL);}else{echo $address[2];} ?>" /> <br /> <input type="text" name="optC4" value="<?php if(empty($address[3])){$address[3] = array(NULL);}else{echo $address[3];} ?>" /> <br /> </td> </form> </body> </html> script code: <!--search function code--> <script type="text/javascript"> $(document).ready(function(){ $("#query").autocomplete({ source : 'search.php', select : function(event,ui){ $("#query").html(ui.item.value); } }); }); </script> search.php page code: <?php $q = $_GET['term']; mysql_connect("localhost","root",""); mysql_select_db("test"); $query = mysql_query("SELECT DISTINCT batchcode FROM tb_app WHERE batchcode LIKE '$q%'"); $data = array(); while($row = mysql_fetch_array($query)){ $data[]=array('value'=>$row['batchcode']); } echo json_encode($data); ?>
  16. I need to pass a variable from html through ajax to php The following code is what I have contacttext is what fells in the data from ajax <select name="contact"type="text" class="form-control input-sm contacttext" id="idcontact"></select> $( document ).ready(function() { $.ajax({ //create an ajax request to load_page.php type: "GET", url: "php/contact.php", dataType: "html", //expect html to be returned success: function(response){ $(".contacttext").html(response); //alert(response); } }); }); $id is what I need to pass threw the ajax script <?php include("connect.php"); $pid = $_SESSION['profile']['id']; echo "<option value=''>SELECT A CONTACT</option>"; foreach($db->query("SELECT * FROM contact WHERE pid = '$pid' AND cid = '$id'") as $row) { echo "<option value=" . $row['cid'] . ">" .$row['contact'] . "</option>"; }
  17. Hello i would require help with the given script AJAX Code (text): $.ajax({ type: "post", url: "http://localhost/raffle.php", dataType: "json", data: { "postraffle": "true", "title": $("#rtitle").val(), "message": $("#mess").val(), "maxentry": $("#maxentry").val(), "duration": $("#durr").val(), "filter": $("#reffil").val(), "split": $("input[name=split]:checked").val(), "pub": $("input[name=rafflepub]:checked").val(), "stype": $("input[name=stype]:checked").val(), "invo": $("input[name=invo]:checked").val(), "items[]": itms, "games[]": gmes, }, success: function(data){ if(data.status == "fail") { alert(data.message); $("#rafBut").removeAttr("disabled"); $("#rafBut").attr("value", "Raffle it!"); } else if(data.status == "ok") { window.location.href = "http://localhost/raffle.php"; } } }); </script> And here is the php script PHP: <?php $data = array( 'status' => 'fail', 'message' => 'Failed to save data', ); echo json_encode($data); You can see the script live here admin.tftrg.com/Prototype/raffle.html I want all of the above data to transmit from HTML using ajax to php i would like to echo all the information from the ajax script to the php script Well currently it shows an error FAILED TO TRANSMIT DATA Some help would be really appreciated Thanks!
  18. I have a table called tb_app with fields 'id','aic','batchcode','name' example table value: '1','0001','1','james'. As you can see there are three textboxes(name)(aic)(batchode). I want to show the value of aic and batchcode in their correspoding textboxes after typing the specific name in the textbox(name). The problem is when you type james in the textbox(name) it shows '00011' in the (aic)textbox and (batchcode)textbox...i want it to be '0001' in aic and '1' in the batchcode if i type james which is stored value in the table. html code: <form method="post"> <input type="text" name="names" id="query" onblur="getvalues()"/> <input type="text" name="aic" id="aic"/> <input type="text" name="batchcode" id="batchcode" /> </form> script code: <script type="text/javascript"> function getvalues() { var selname = $("input[name=names]:text").val(); $.ajax({ url: "getuserdata.php", data: {"selname":selname}, type: 'post', success: function(output) { $("#aic").val(output); $("#batchcode").val(output); } }); } </script> getuserdata.php page: <?php include('include/connect.php'); $selname = $_POST['selname']; $query = "SELECT * FROM tb_app WHERE tb_app.name RLIKE '$selname'"; $result = mysql_query($query) or die(mysql_error()); while($rows = mysql_fetch_array($result)){ echo $rows['aic']; echo $rows['batchcode']; } ?>
  19. So I have a webpage where I pull several rows from the database and create a list on the webpage. Any one of these rows can get updated independently at any time. For the past several years I've used something like this: function execRefresh() { $("#refreshIcon").fadeIn("fast"); $("#'. $p .'").load("/data.php?inid='. $p .'&rand=" + Math.random(), "", function () { $("#refreshIcon").fadeOut("slow"); } ); setTimeout(execRefresh, 20000) } $(document).ready(function () { execRefresh(); }); This will reload the entire content from the database to repopulate the list on the webpage. I'm wondering if there is a better way to do this. The downfalls I'd like to overcome if possible would be (and I realize these two overlap a bit): 1. I am loading the entire table for everyone on the webpage even if there are no changes (unnecessary loads/database pings). - Is there a way to only pull new data if there is a change? - Is there a way to only pull the rows that got changed? - Is there a way to make it so that I don't have to make a call to the database for every single user? 2. I have to create an interval to determine how often I reload the data. Currently I have 20 seconds, this means if an update occurs right after the user loaded data, it could be up to 20 seconds before they see that change (not loading when necessary). - Is there a way to tell the client there has been a change and it needs to update so that it doesn't have extended periods of time where the data isn't updated without just making the interval shorter (and thus having more unnecessary loads)? I know that, for example, Google chat is nearly instantaneous in telling you "Someone is typing" and then showing what they sent as a chat. I imagine that they don't have millions of users constantly pinging a database that contains the chats and whether or not a user is currently typing every second. What would the best way to do this be? I assume it's relatively common and there are possibly some best practices for things such as this. Thanks
  20. hi im new at prestashop and i need to know a couple things so i can change a query for the search... i need to know how to have the php search for a product id and the product from two different tables ... is this the code that uses the word from the search box to look in the database tables or is this the wrong query ? im just trying to find the query public static function find($id_lang, $expr, $page_number = 1, $page_size = 1, $order_by = 'position', $order_way = 'desc', $ajax = false, $use_cookie = true, Context $context = null) { if (!$context) $context = Context::getContext(); $db = Db::getInstance(_PS_USE_SQL_SLAVE_); // Only use cookie if id_customer is not present if ($use_cookie) $id_customer = $context->customer->id; else $id_customer = 0; // TODO : smart page management if ($page_number < 1) $page_number = 1; if ($page_size < 1) $page_size = 1; if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) return false; $intersect_array = array(); $score_array = array(); $words = explode(' ', Search::sanitize($expr, $id_lang)); foreach ($words as $key => $word) if (!empty($word) && strlen($word) >= (int)Configuration::get('PS_SEARCH_MINWORDLEN')) { $word = str_replace('%', '\\%', $word); $word = str_replace('_', '\\_', $word); $intersect_array[] = 'SELECT si.id_product FROM '._DB_PREFIX_.'search_word sw LEFT JOIN '._DB_PREFIX_.'search_index si ON sw.id_word = si.id_word WHERE sw.id_lang = '.(int)$id_lang.' AND sw.id_shop = '.$context->shop->id.' AND sw.word LIKE '.($word[0] == '-' ? ' \''.pSQL(Tools::substr($word, 1, PS_SEARCH_MAX_WORD_LENGTH)).'%\'' : '\''.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\'' ); if ($word[0] != '-') $score_array[] = 'sw.word LIKE \''.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\''; } else unset($words[$key]); if (!count($words)) return ($ajax ? array() : array('total' => 0, 'result' => array())); $score = ''; if (count($score_array)) $score = ',( SELECT SUM(weight) FROM '._DB_PREFIX_.'search_word sw LEFT JOIN '._DB_PREFIX_.'search_index si ON sw.id_word = si.id_word WHERE sw.id_lang = '.(int)$id_lang.' AND sw.id_shop = '.$context->shop->id.' AND si.id_product = p.id_product AND ('.implode(' OR ', $score_array).') ) position'; $sql = 'SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg INNER JOIN `'._DB_PREFIX_.'category_product` cp ON cp.`id_category` = cg.`id_category` INNER JOIN `'._DB_PREFIX_.'category` c ON cp.`id_category` = c.`id_category` INNER JOIN `'._DB_PREFIX_.'product` p ON cp.`id_product` = p.`id_product` '.Shop::addSqlAssociation('product', 'p', false).' WHERE c.`active` = 1 AND product_shop.`active` = 1 AND product_shop.`visibility` IN ("both", "search") AND product_shop.indexed = 1 AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN ( SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.(int)$id_customer.' )'); $results = $db->executeS($sql);
  21. hi, i am not gud in ajax. i have this code... <html> <head> <title>Sum Html Textbox Values using jQuery/JavaScript</title> <style> body { font-family: sans-serif; } #summation { font-size: 18px; font-weight: bold; color:#174C68; } .txt { background-color: #FEFFB0; font-weight: bold; text-align: right; } </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> </head> <body> <table width="300px" border="1" style="border-collapse:collapse;background-color:#E8DCFF"> <tr> <td width="40px">1</td> <td>Butter</td> <td><input class="txt" type="text" name="txt"/></td> </tr> <tr> <td>2</td> <td>Cheese</td> <td><input class="txt" type="text" name="txt"/></td> </tr> <tr> <td>3</td> <td>Eggs</td> <td><input class="txt" type="text" name="txt"/></td> </tr> <tr> <td>4</td> <td>Milk</td> <td><input class="txt" type="text" name="txt"/></td> </tr> <tr> <td>5</td> <td>Bread</td> <td><input class="txt" type="text" name="txt"/></td> </tr> <tr> <td>6</td> <td>Soap</td> <td><input class="txt" type="text" name="txt"/></td> </tr> <tr id="summation"> <td> </td> <td align="right">Sum :</td> <td align="center"><span id="sum">0</span></td> </tr> </table> <script> $(document).ready(function(){ //iterate through each textboxes and add keyup //handler to trigger sum event $(".txt").each(function() { $(this).keyup(function(){ calculateSum(); }); }); }); function calculateSum() { var sum = 0; //iterate through each textboxes and add the values $(".txt").each(function() { //add only if the value is number if(!isNaN(this.value) && this.value.length!=0) { sum += parseFloat(this.value); } }); //.toFixed() method will roundoff the final sum to 2 decimal places $("#sum").html(sum.toFixed(2)); } </script> </body> </html> ..........................from net. this will add all the input fields and give us the total of it. but i want one more input field in which when i put some value . then, total amount should be subtracted from it and gives the result.. can anyone give me some suggestions.... please ????? thanks.
  22. Hi there, My head is stuck at this moment. I've got a textfile with words. Each word starts at a new line. I want to let the user delete a word(line) from this textfile after a button click. I managed to add the "add word to the list" function, but now i want a delete button variant. There are four files. myscript.js, vulwoorden.txt, word_filter.php and delete.word.php. This is the code for myscript.js: //User can add word to wordfilter $("body").on("click", ".hide_word", function(e){ e.preventDefault(); var word = $(this).data("word"); $.ajax({ url: 'includes/set.word.php', type: 'POST', data: 'word=' + word, success: function (){ }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError); } }); $(this).parent().parent().hide('slow', function(){ $(this).remove(); }); }); //User can delete word from wordfilter $("body").on("click", ".delete_word", function(e){ e.preventDefault(); var word = $(this).data("word"); $.ajax({ url: 'includes/delete.word.php', type: 'POST', data: 'word=' + word, success: function (){ }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError); } }); $(this).parent().parent().hide('slow', function(){ $(this).remove(); }); }); This is the code for the word_filter page <?php $lines = file('./includes/vulwoorden.txt'); $i=1; echo '<table id="wordlist" class="table">'; foreach ($lines as $line_num) { echo '<tr>' . "<td>" . $line_num . '</td><td>'; echo '<a data-word="' . $line_num . '" class="btn-danger btn-sm delete_word">Verwijder woord</a></td></tr>'; $i++; echo '</table>'; ?> And this is the code for delete.word.php (this code is just a copy from the set.word.php, so this is code to add a word to the textfile. <?php $fn = "vulwoorden.txt"; $file = fopen($fn, "a+"); if(isset($_POST['word']) && trim($_POST['word']) != "" && !is_null($_POST['word'])) { $word = $_POST['word'] . "\r\n"; fwrite($file, $word); } ?> I know how to do it with a form, but i want to do it combined with Ajax, so the users won't have to refresh the page. Thanks in advance!!
  23. I need some help. Im trying to call a php function in ajax. The data variable needs to be inside the called function. Like: _("statusarea").innerHTML = '<div><?php showBBcodes('+data+'); ?></div>'; But no matter what i do it wont call it and if it does call it it wont show the data.
  24. hello I have a php file name abc.php . in that i call db connection file. in same file i want to call data from another php file. then i did following code $.ajax({ type: "GET", url: 'aa.php', data: "fid=" + fid, $(ffid).html(data); i want to know when we use following jquery code then it call aa.php then that also contain the same db connection file my question is when i call connection file in abc.php and then same time i call aa.php using ajax then database connection file include 2 times then 2 connection will open or when we open connection once then again it do not open again even i call 10 php files using ajax? or if call 10 php files using aax and all have conn file then 10 more connections will open? How exactly db connection work when open once
  25. Hello! Second post here. I'm new to PHP and have an idea of what needs to be done, but im not sure the best way to impliment it. Basically im looking for direction on whether I should use JS, AJAX, Jquery, or something else. from browsing around im guessing its going to be a combination of AJAX and Jquery to get this accomplished. Please advise on the best method to acomplish this. Thanks =) The user needs to populate txtAddr and hit btnGen. The function will then confirm txtAddr is equal to a variable. If it is equal, populate other 2 text fields (txtKey & txtDest) with predefined variables. <form action="frmGen" method="post"> <input name="txtAddr" type="text"> <!-- User enters text here -- Confirm txtAddr.text = $VarAddr -- If True, continue. If False, display DIV message --> <input name="txtDest" type="text"> <!-- Text field is filled with value from server/SQL when btnGen is pressed--> <input name="txtKey" type="text"> <!-- Text field is filled with value from server/SQL when btnGen is pressed--> <input name="btnGen" type="button"> <!-- assuming txtAddr is True, display strings in 2 text fields above & store all values from 3 text boxes in SQL --> </form>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.