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 a flashcard program to teach Japanese vocabulary. I want to add sound files from native speakers so I have created a page with a recorder that 1. displays a word (on load) 2. allows the native speaker to record the word (on press of a button) 3. uploads the recording to the server (on press of another button) I wrote the word display as a separate php script so that I could use Ajax to just change the word being recorded, so that I would not need to reload the entire page every time the speaker switched to a new word. The js that gets the word to be recorded is: function ajaxRequest(){ //declare the variable at the top, even though it will be null at first var req = null; //modern browsers req = new XMLHttpRequest(); //setup the readystatechange listener req.onreadystatechange = function(){ //right now we only care about a successful and complete response if (req.readyState === 4 && req.status === 200){ //inject the returned HTML into the DOM document.getElementById('cardData').innerHTML = req.responseText; }; }; //open the XMLHttpRequest connection req.open("GET","nextcard.php",true); //send the XMLHttpRequest request (nothing has actually been sent until this very line) req.send(); }; The section that uploads the file is: $('#send').click(function(){ $.jRecorder.sendData(); } and it gets the filename from another script: $.jRecorder( { host : 'http://localhost:10088/NewFolder/japanese/jrecorder/acceptfile.php?filename=hello.wav' The problem that I have is that when I get each word I want to change the name of the file being uploaded. It all works and if I reloaded the page each time I could do this: $.jRecorder( { host : 'http://localhost:10088/NewFolder/japanese/jrecorder/acceptfile.php?filename=<?php echo $word.'_'.$reader_id;?>.wav' but I want to stay on the Ajax path. So, I think that I need to convert the newcard program to return json with something like: $response=array(filename=>$word.$reader_id, card_data=>$card_stuff); echo json_encode($response); but once I get the json back I don't see how I get the filename into the script that sets the upload url and make that script re-execute. Is there a reasonable way to do that?
  2. Greetings all, Been trying to make a plugin in wordpress and ran into an issue with the way wordpress makes use of ajax in the administration menu. The problem is that I completely don't understand it. I've read all the docs on it and even tried messing with a variety of tutorials on the matter to no avail. What I am trying to do is a simple task outside of wordpress. The form has two select fields, the first field populates the second selection field. While this works fine on a standard html page, trying to do it in wordpress is another story. Form.php: <div id="wrapper"> <h1>Second dropdown selection based </h1> <form action="" method="post"> <p><label>Main Menu :</label> <select name="main_menu_id" id="main_menu_id"> <option value="">Select</option> <?php // Connect to database. $connect = mysqli_connect('<!--DB connection info-->"); $q = mysqli_query($connect, "SELECT cfid,cfname FROM categoryfiles ORDER BY cfid"); while($row = mysqli_fetch_array($q)) { echo '<option value="' . $row['cfname'] . '">' . $row['cfname'] . '</option>'; } ?> </select> </p> <p><label>Sub Menu: </label> <select name="sub_menu_id" id="sub_menu_id"></select> </p> </form> </div> The script.js $(function() { $("#main_menu_id").bind("change", function() { $.ajax({ type: "GET", url: "scripts/get_sub_category.php", data: "main_menu_id="+$("#main_menu_id").val(), success: function(html) { $("#sub_menu_id").html(html); } }); }); }); The get_sub_category.php <?php // Connect to database. $connect = mysqli_connect('<!--My connection info-->); $id = $_GET['main_menu_id']; $q = mysqli_query($connect, "SELECT sfid, sfname FROM subjectfiles WHERE sfcategory='" . $id . "' ORDER BY sfname"); while($row = mysqli_fetch_array($q)) { echo '<option value="' . $row['sfname'] . '">' . $row['sfname'] . '</option>'; } ?> Like I said, it works just fine outside of wordpress so really I just need help getting it to work in wordpress. I just don't understand it. Thanks to anyone that takes the time to look this over. Best Regards, Nightasy
  3. Hello, Here is my current code: index.php <html> <body> <form id="hey" name="hey" method="post" onsubmit="return false"> Name:<input type="text" name="name"> <input type="submit" name="submit" value="click"> </form> <table class="table table-bordered" id="update"> <thead> <th>Name</th> </thead> <tbody> <script type="text/javascript"> $("#hey").submit(function() { $.ajax({ type: 'GET', url: 'response.php', data: { username: $('#name').val()}, success: function (data) { $("#update").prepend(data); }, error: function (xhr, ajaxOptions, thrownError) { alert(thrownError); } }); }); </script> </tbody> </table> response.php <?php $username = $_GET['username']; echo "<tr>"; echo "<td>$username</td>"; echo "</tr>"; ?> This code works fine, it prints out the rows as what the user enters. Now what I want to do is, log all these entries to a mySQL database and also, display these rows over the site. i.e., any user who is online, should be seeing this without having to refresh the page too.. Real time updates in a way. How can I achieve that? Thanks!
  4. Hi I have an AJAX call that populates a select menu based on the selection from a previous menu. All works on on desktop browser, Safari, Firefox IE etc, however when using iOS the second select menu isn't populating. the AJAX request is as follows <script> function getXMLHTTP() { //fuction to return the xml http object var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getTeam(strURL) { var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('away-team').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } function getGP(strURL) { var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('gp').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script> and the trigger for it... <select name="year" class="txtfield" onChange="getGP('find_gp_ajax.php?season='+this.value)"> Any ideas why the call won't work on iOS?
  5. Here is my java script $.each(data, function() { var myTable1 = '<tr bgcolor=#ffffff>' + '<td align=center>'+this.vehiclelog_plate+'</td>' + '<td align=center>'+this.vehiclelog_name+'</td>' + '<td align=center>'+this.vehiclelog_date+'</td>' + '<td align=center>'+this.vehiclelog_reftype+'</td>' + '<td align=center>'+this.vehiclelog_refid+'</td>' + '<td align=center>'+this.vehiclelog_description+'</td>' + '</tr>'; $('#tableField').append(myTable1); }); And here is my HTML <div id="tabs-6"> <div id="rform"> <form action = "home.php" method="post"> <fieldset> <legend>View Vehicle Service</legend><br><br> <div> <label class="label-left">Vehicle Name:</label> <span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span> <input id="autocomplete" title="type "a"" class="ui-autocomplete-input" name="vehicle_service_search" autocomplete="off"> </div> <div> <button id="searchVehicleDesc" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"> <span class="ui-button-text">View</span> </button> </div> <div> <table border="1" width="650" id = "tableField"> <tr bgcolor=#c0c0c0> <td width=100 align="center"><font face="helvetica"><b>Vehicle Name</b></font></td> <td width=80 align="center"><font face="helvetica"><b>Service Type</b></font></td> <td width=80 align="center"><font face="helvetica"><b>Others</b></font></td> <td width=100 align="center"><font face="helvetica"><b>Reference No.</b></font></td> <td width=80 align="center"><font face="helvetica"><b>Reference Date</b></font></td> <td width=80 align="center"><font face="helvetica"><b>Reference Type</b></font></td> </tr> </table> </div> </fieldset> </form> </div> </div> And here is my response [{"success":1,"plate":"SIX666","name":"YAMAHA ISUZU","date":"0000-00-00","type":"Add Vehicle","id":"0","desc":""},{"success":1,"plate":"VIE597","name":"Resource id #6","date":"2014-05-09","type":"OIL","id":"332142","desc":"castroil"}] Im getting the right response from ajax but I can't put my value to a table I get an alert that says undefined.
  6. I know how to implement ajax with php and get output with the help of java-script and ajax... Well, I am just trying to re-direct the page using ajax, but, it is not happening........ What I am doing is that after user logged-in successfully, the email and password are going to check by ajax and if the inputs are correct, the page must re-direct to another page... So, far I am able to verify the correct details, but, the page is not re-directing... You must also see that I want to re-direct the page with ajax only................I am able to redirect the page with java-script but I do not want to include re-direction with java-script in my website !! Thanks for helping me out !!
  7. I have a script that allows me to post comments, but when i try to delete that comment i get a error message telling me that a specific variable is undefined. I refresh the page and try again, and suddently it works. template_test.php <?php if($author == $log_username || $account_name == $log_username ){ $statusDeleteButton = '<span id="sdb_'.$statusid.'"><a href="#" onclick="return false;" onmousedown="deleteStatus(\''.$statusid.'\',\'status_'.$statusid.'\',\''.$DB_table.'\');" title="DELETE THIS STATUS AND ITS REPLIES">delete status</a></span> '; } ?> <script> function deleteStatus(statusid,statusbox,document){ var ajax = ajaxObj("POST", "php_parsers/status_system2.php"); ajax.onreadystatechange = function() { if(ajaxReturn(ajax) === true) { if(ajax.responseText === "delete_ok"){ // remove the div all of the tekst is inside, the textarea and the reply button _(statusbox).style.display = 'none'; _("replytext_"+statusid).style.display = 'none'; _("replyBtn_"+statusid).style.display = 'none'; } else { alert(ajax.responseText); } } } ajax.send("action=delete_status&statusid="+statusid+"&document="+document); }; </script> php_parsers/status_system2.php <?php // fires of when the someone deletes a thread if (isset($_POST['action']) && $_POST['action'] == "delete_status" && !empty($_POST['document'])){ if(!isset($_POST['statusid']) || $_POST['statusid'] == ""){ echo "status id is missing"; exit(); } // sanitize the inserted status id $statusid = preg_replace('#[^0-9]#', '', $_POST['statusid']); // check to see which page the user is on, then give different variables that contain different DB tables // check to see whether or not the user replied to a status from user.php or watch.php if($_POST['document'] == "comments") // this means the user replied within watch.php { $DB_table = "comments"; } else if($_POST['document'] == "status") // this mean that the user replied within user.php { $DB_table = "status"; }else{ echo 'Error: this is an unexpected situation. What is happening? ' . $_POST['document']; } // Check to make sure the person deleting this reply is either the account owner or the person who wrote it if($DB_table == null){ echo 'Can\'t look up nuthin'; }else{ // Check to make sure the person deleting this reply is either the //account owner or the person who wrote it $sql = "SELECT account_name, author FROM $DB_table WHERE id='$statusid' LIMIT 1"; $query = mysqli_query($con, $sql); while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) { $account_name = $row["account_name"]; $author = $row["author"]; } } // delete the thread and it replies with the same osid if ($author == $log_username || $account_name == $log_username) { $sql = "DELETE FROM $DB_table WHERE osid='$statusid'"; mysqli_query($con, $sql); echo "delete_ok"; exit(); } } ?>
  8. Hi, I'm trying to let JavaScript check if a givin user exist in the database. It seems that the _check-user.php always returns 0, but if I fill in a name that doesn't exist, and echo out the result variable in JS, the echo will return 1. Is there someone who could help me? JavaScript part: function checkUser() { $.post("_check_user.php", { 'username': document.getElementById("username").value }, function(result) { if (result == 1) { document.getElementById("checkUser").className = "succes"; document.getElementById("checkUser").innerHTML = "Name is available"; }else{ document.getElementById("checkUser").className = "errormsg"; document.getElementById("checkUser").innerHTML = "Name is not available!"; } }); } _check-user.php: <?php include("config.php"); $result = mysql_query("SELECT login FROM users WHERE login='".clean_string($_POST["username"])."'"); if(mysql_num_rows($result)>0){ echo 0; }else{ echo 1; } ?>
  9. Here is my button $( "#editVehicle" ).button().click(function( event ) { event.preventDefault(); var vp = $("input[name=vehicle_plate]").val(), dataString = 'vehicle_plate='+ vp; $.ajax({ type: "POST", url: "editvehicle.php", data: dataString, dataType: "json", success: function(data){ if(!data.error && data.success) { $("input[name=vehicle_model]").val(data.vehicleName); $("input[name=assigned_driver]").val(data.assignedDriver); } else { alert(data.errorMsg); } } }); }); And here is my PHP <?PHP include("db.classes.php"); $g = new DB(); $g->connection(); if($_POST) { $vehiclePlate = $g->clean($_POST["vehicle_plate"],1); $g->edit($vehiclePlate); } $g->close(); ?> and here is my db.classes public function edit($vehiclePlate) { $sql = "select vehicle_name, driver_id from vehicles where vehicle_plate='$vehiclePlate'"; $result = mysql_query($sql) or die(json_encode(array("error" => 0, "errorMsg" => "MySQL query failed."))); $row = mysql_fetch_array($result); if(mysql_num_rows($row)) { echo json_encode(array( "success" => 1, "vehicleName" => $row['vehicle_name'], "assignedDriver" => $row['driver_id'] )); } else { echo json_encode(array( "error" => 1, "errorMsg" => "No rows returned" )); } } There is an input field in my html where i input the vehicle plate then when the user clicks the button the program searches the database for the vehicle name and driver_id with the plate the user entered and returns the value to another inputfield named "vehicle_name" and "assigned_driver" but nothing is happening when the button is clicked not even the error alert message. Any idea on where am i going wrong here?
  10. Here is my ajax $(".submit").click(function(){ var vp = $("input#vehicle_plate").val(); var vm = $("input#vehicle_model").val(); var vt = $("input#vehicle_type").val(); var da = $("input#date_acquired").val(); var ad = $("input#assigned_driver").val(); var dataString = 'vehicle_plate='+ vp + '&vehicle_model='+ vm + '&vehicle_type='+ vt + '&date_acquired='+ da + '&assigned_driver='+ ad; $.ajax({ type: "POST", url: "process.php", data: dataString, success: function(){ $('.success').fadeIn(200).show(); $('.error').fadeOut(200).hide(); } }); return false; }); And here is my PHP where i pass my 'dataString' <?PHP include("db.classes.php"); $g = new DB(); $g->connection(); if($_POST) { $vehiclePlate = $g->clean($_POST["vehicle_plate"],1); $vehicleModel = $g->clean($_POST["vehicle_model"],1); $vehicleType = $g->clean($_POST["vehicle_type"]); $assignedDriver = $g->clean($_POST["assigned_driver"],1); $ad = date('Y-m-d', strtotime($_POST["datepicker"])); $g->add($vehiclePlate, $vehicleModel, $vehicleType, $assignedDriver, $ad); } $g->close(); ?> And here is my database query public function add($vehiclePlate, $vehicleModel, $vehicleType, $assignedDriver, $ad) { $sql = "insert into vehicles(`vehicle_plates`,`DA`,`type`, `model`, `driver`) values('$vehiclePlate', '$ad', '$vehicleType', '$vehicleModel', '$assignedDriver')"; if(!mysql_query($sql)) { $this->error = mysql_error(); return true; } else { return false; } } the AJax is succesful but when i try and see the table in my databse the inserted row are al 'Undefined' what seems to be causing this?
  11. <script> $('.add_to').click(function(){ //alert(1); productId= $(this).attr('id'); //var grandTotal= $('#grandTotal').html(''); $('#sucessAdd').html('<img src="images/ajax-loader.gif" align="center" />'); //var grandTotalfloat= parseFloat(grandTotal); $.ajax({ type: "POST", url:"pass.php", data: {action:'addCatalog',productId:productId}, success:function(result){ //alert(result) if(result==1){//add_to_cat $('#'+productId).remove(); $('#'+productId).fadeTo("fast", .5); $('#sucessAdd').html(''); //$('#sucessAdd').css('color','green'); $('#sucessAdd').addClass('add-sucess'); $('#sucessAdd_'+productId).html('<font coloe="red"><b>Add Successfully</b></font>'); $("#"+productId).style.display="block"; } } }) }); </script> <div class="items_box_link"> <a href="#" id="<?php echo $productRow['id'];?>" class="add_to">ADD TO CART</a> </div> ..........................................////////////////////////////............................................ after add to cart, my page goes to top but i want it to remain dere only.. any help!.. thanks.
  12. In my mail sending script powering my contact form, the mail sending action can take some time, during this time the user doesn't know what happens. So, I wanted to add a "Mail Sending..." notification. While my application is working fine. When I added the notification module, the notification is not appearing. I shall appreciate a way out on how to resolve this. Find below the AJAX script and html form code. <script> $(document).ready(function(){ $('#submit').click(function(){ $.post("send.php", $("#mycontactform").serialize(), function(response) { $('#success').html(response); }); return false; }); }); </script> And this is the contact form html code: <form action="" method="post" id="mycontactform" > <label for="name">Name:</label><br /> <input type="text" name="name" id="name" /><br /> <label for="email">Email:</label><br /> <input type="text" name="email" id="email" /><br /> <label for="message">Message:</label><br /> <textarea name="message" id="message"></textarea><br /> <input type="button" value="send" id="submit" /> <div id="success" style="color:red;"></div> </form> I read up on the .ajaxStart( handler() ) event on https://api.jquery.com/ajaxStart/, but implementing this solution which i thought may solve the problem is not working: $(document).ready(function(){ $('#submit').click(function(){ $.post("send.php", $("#mycontactform").serialize(), function(response) { $('#success').html(response); }); return false; }); $( document ).ajaxStart(function() { $( "#success" ).show('Mail Sending, Please Wait'); }); }); Kindly assist. Thanks,
  13. All I want to do is simply delete a record/row using ajax. For the life of me, I can't get it to work. I have tried many different methods and played around with them. Here is a basic example. Please do tell me what's wrong with it and how I can fix it. index.php <html> <head> <title>Home page</title> <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script> $(document).ready(function() { $(function() { $(".del-action").click(function() { var commentContainer = $(this).parent(); var id = $(this).attr("id"); var string = 'id='+ id ; $.ajax({ type: "GET", url: "delete.php", data: string, cache: false, }); }); </script> </head> <body> <?php $get = DB::getInstance()->query("SELECT * FROM records WHERE record_id = 28 "); if(!$get->count()) { echo 'no record found!'; } else { foreach($get->results() as $row) { $record_id = $row->record_id; ?> <div class="record"> <a href="#" class="del-action" id="<?php echo $record_id; ?>" >Delete</a> </div> <?php } } ?> </body> </html> delete.php $record_id = intval($_GET['id']); $delete = DB::getInstance()->delete('records', array('record_id', '=', $record_id)); ps. it deletes the records fine without ajax/js. I just need help with the js code so that I can delete the record without redirecting or refreshing the page.
  14. I have a basic username/password form that uses AJAX to login: Submit the two values in an AJAX request If the values are correct, sets session variable for the user and returns success Client receives success and redirects to the start page. All of this is basic stuff, works fine. But now some customers say they want the form to remember passwords. I've done some basic work: Added FORM tags around these input fields. Returns false Gave the input fields NAME attributes This seems to make Firefox prompt to remember the password. But I'm having no luck with Chrome, IE, or Safari. I've googled extensively and there are basically two or three solutions, but I can't get anything to work on these other browsers. It's getting to be quite frustrating. I'm thinking of abandoning this AJAX form and just going to crappy old POST. What are you using for AJAX login pages? Are passwords remembered by the browser? How are you doing it?
  15. I am trying to have a js alert box to confirm before deleting a record. Here is the js code. <script> function confirmation() { var answer = confirm("Are you sure?") if (answer){ alert("This record been deleted!") } else{ alert("Not deleted!") } } </script> php code. <a href="delete.php" onclick="confirmation()">Delete record</a> The problem is, even if i click no in the js alert box and the message shows("Not deleted!"), it still deletes the record. Why is it doing that? My second question is, is it possible to css the js alert box? I need to customize it to my own look.
  16. This is a script that validates a user's email and password. Everything is super clear but I can't figure out the purpose of document.getElementById('theForm').submit(); As far as I know, it's a method that submits the form to the script referenced inside the forms html action tag eg. <form action="login.php"> (just in case ajax fails for whatever reason). But I can't find any information to validate this. function validateForm() { 'use strict'; // Get references to the form elements: var email = document.getElementById('email'); var password = document.getElementById('password'); // Validate! if ( (email.value.length > 0) && (password.value.length > 0) ) { // Perform an Ajax request: var ajax = getXMLHttpRequestObject(); ajax.onreadystatechange = function() { if (ajax.readyState == 4) { // Check the status code: if ( (ajax.status >= 200 && ajax.status < 300) || (ajax.status == 304) ) { if (ajax.responseText == 'VALID') { alert('You are now logged in!'); } else { alert('The submitted values do not match those on file!'); } } else { document.getElementById('theForm').submit(); } } }; ajax.open('POST', 'resources/login.php', true); ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); var data = 'email=' + encodeURIComponent(email.value) + '&password=' + encodeURIComponent(password.value); ajax.send(data); return false; } else { alert('Please complete the form!'); return false; } } // End of validateForm() function. // Function called when the window has been loaded. // Function needs to add an event listener to the form. function init() { 'use strict'; // Confirm that document.getElementById() can be used: if (document && document.getElementById) { var loginForm = document.getElementById('loginForm'); loginForm.onsubmit = validateForm; } } // End of init() function. // Assign an event listener to the window's load event: window.onload = init;
  17. I was following a tutorial from else where that showed how to do dynamic dropdown with ajax. Unfortunatly he only does it for two drop downs. I need a third dropdown. I have a dropdown for select country and select region. They work great. How can I add the select city dropdown as well with js? js code on index.php <html> <head> <script> function showHint(str) { var xmlhttp; if (str.length==0) { document.getElementById("regiondiv").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("regiondiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","geo.php?country="+str,true); xmlhttp.send(null); } </script> </head> <body> <div class="field"> <label for="cat">Country</label> <select id="country" name="country" onChange="showHint(this.value);" required > <option value="0">--Select Country--</option> <?php $getCountry = DB::getInstance()->query("SELECT * FROM countries"); if(!$getCountry->count()) { echo 'No Country found!'; } else { foreach($getCountry->results() as $row) { $country_id = escape($row->countryId); $country_name = escape($row->countryName); ?><option value="<?php echo $country_id; ?>" ><?php echo $country_name; ?></option><?php } } ?> </select> </div> <label for="cat">Region</label> <div id="regiondiv"> <select name="region" id="region"> <option>--Select State--</option> <option></option> </div> </body> </html> ajax.php <?php require_once 'core/init.php'; $country_id = escape(Input::get('country')); $select_region = DB::getInstance()->get('regions', array('countryId', '=', $country_id)); if(!$select_region->count()) { echo 'No Country found!'; } else { ?><select name="region" id="region"><?php foreach($select_region->results() as $row) { $region_id = escape($row->regionId); $region_name = escape($row->regionName); ?><option value="<?php echo $region_id; ?>" ><?php echo $region_name; ?></option><?php } ?></select><?php }
  18. So I have this problem with AJAX. I want to pass the value from the selected dropdown with ajax so that when user selected one of the value in dropdown list(from Oracle DB) it pulls the corresponding value and send it inside the page for processing. So the database schema is like this, HEAD_MARK QTY CUTTING ASSEMBLY WELDING DRILLING FINSHING --------------- ---------- ---------- ---------- ---------- ---------- --------- TEST-2 222 0 0 0 0 0 INI TEST 999 0 0 0 0 0 TEST_RUN1 11 2 2 2 2 2 and my Demo.php is like this. It pulls the Head_mark value from the database and direcly passing the value to process the, 1. Show the corresponding quantity 2. Use the quantity to compare the cutting. Lets say cutting value in the db today is 2 and the quantity is 10. So in the input tag, min="2" and max="10". And user can input new value and update it to the database according to the selected input <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> function OnSelectionChange (select) { var selectedOption = select.options[select.selectedIndex]; //some ajax checkpoint for checking value //alert ("The selected option is " + selectedOption.value); jQuery.ajax({ url: location.href, data: {'hm':selectedOption.value, 'ajax':1}, type: "POST", success: function( data ) { jQuery("#lbl_qty").html(data);//PRINT QTY TO THE SCREEN } }); //some ajax checkpoint //alert('after ajax'); } $(function(){ //insert record $('#insert').click(function(){ var jcutting = $('#fcutting').val(); var jassembly = $('#fassembly').val(); var jwelding = $('#fwelding').val(); var jdrilling = $('#fdrilling').val(); var jfinishing = $('#ffinishing').val(); //syntax - $.post('filename', {data}, function(response){}); $.post('../update_bar/data.php', {action: "insert", cutting:jcutting, assembly:jassembly, welding:jwelding, drilling:jdrilling, finishing:jfinishing}, function(res){ $('#result').html(res); });}); //show records $('#show').click(function(){ $.post('data.php',{action: "show"},function(res){ $('#result').html(res); }); }); }); </script> </head> <body> <?php // DROPDOWN VALUES TO PULL COMPONENT FROM THE DB $result = oci_parse($conn, 'SELECT HEAD_MARK FROM FABRICATION'); oci_execute($result); echo '<SELECT name="headmark" id="headmark" onchange="OnSelectionChange(this.value)">'.'<br>'; echo '<OPTION VALUE=" ">'."".'</OPTION>'; while($row = oci_fetch_array($result,OCI_ASSOC)){ $HM = $row ['HEAD_MARK']; echo "<OPTION VALUE='$HM'>$HM</OPTION>"; } echo '</SELECT>'; ?> <?php // IT DIRECTLY SHOWS THE QUANTITY FOR THE GIVEN HEADMARK WHEN USER SELECT ONE OF THE HEADMARK FROM THE DROPDOWN // BUT IT SHOWS Notice: Undefined index: hm in C:\xampp\htdocs\WeltesInformationCenter\update_bar\demo.php on line 95 $qty_query_result = oci_parse($conn, "SELECT QTY FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'"); oci_execute($qty_query_result); oci_bind_by_name($qty_query_result, 'QTY', $quantity); echo 'QUANTITY :'.$quantity; ?> <!-- MAX PLACEHOLDER SHOULD BE GATHERED FROM THE QUANTITY FROM THE CORRESPONDING COMPONENT--> Cutting: <input type="number" min="0" id="fcutting" /> Assembly: <input type="number" min="0" id="fassembly" /> Welding: <input type="number" min="0" id="fwelding" /> Drilling: <input type="number" min="0" id="fdrilling" /> Finishing: <input type="number" min="0" id="ffinishing" /> <button id="insert">Insert</button> <h2>Show Records</h2> <button id="show">Show</button> <p>Result:</p> <div id="result"></div> </body> </html> And the Data.php looks like this <?php //if insert key is pressed then do insertion if($_POST['action'] == 'insert'){ $cutting = $_POST['cutting']; $assembly = $_POST['assembly']; $welding = $_POST['welding']; $drilling = $_POST['drilling']; $finishing = $_POST['finishing']; $sql = "UPDATE FABRICATION SET CUTTING = '$cutting', ASSEMBLY = '$assembly', WELDING = '$welding', DRILLING = '$drilling', FINISHING = '$finishing' WHERE HEAD_MARK = '{$_POST["hm"]}''"; $query = oci_parse($conn, $sql); $query_exec = oci_execute($query); if($query_exec){ oci_commit($query_exec); echo "Record Inserted."; }else { echo "Something Wrong!"; } } //if show key is pressed then show records if($_POST['action'] == 'show'){ $sql = "select * from FABRICATION WHERE HEAD_MARK = 'TEST_RUN1'"; $query = oci_parse($conn, $sql); $query_exec = oci_execute($query); echo "<table border='1'>"; while($row = oci_fetch_assoc($query)){ echo "<tr><td>$row[HEAD_MARK]</td><td>$row[CUTTING]</td><td>$row[ASSEMBLY]</td><td>$row[WELDING] </td><td>$row[DRILLING]</td><td>$row[FINISHING]</td></tr>"; } echo "</table>"; } ?> So basically I dont know how to pass the head_mark value to the function in Data.php. The error is like this, Notice: Undefined index: hm in C:\xampp\htdocs\WeltesInformationCenter\update_bar\data.php on line 35 Warning: oci_parse(): ORA-01756: quoted string not properly terminated in C:\xampp\htdocs\WeltesInformationCenter\update_bar\data.php on line 36 Warning: oci_execute() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\WeltesInformationCenter\update_bar\data.php on line 37 Something Wrong! PLease any kind of help would be appreciated
  19. Hello all, I am designing a program that consists of 1 dropdown list that pulled the value from the ORACLE DB and update the value as we change the Dropdown. I can get everything works except the submit button when we want to update the value. Please help me, I know this is a very simple problem but somehow it doesnt work. Your help with greatly appreciated. Thanks, // ASSUME CONNECTION IS DONE if (isset($_POST["ajax"]) && $_POST["ajax"] == 1) { $sql = "SELECT QTY FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'"; $cutting_sql = "SELECT CUTTING FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'"; $assembly_sql = "SELECT ASSEMBLY FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'"; $welding_sql = "SELECT WELDING FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'"; $drilling_sql = "SELECT DRILLING FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'"; $finishing_sql = "SELECT FINISHING FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'"; $stid = oci_parse($conn, $sql); $stid_cutting = oci_parse($conn, $cutting_sql); $stid_assembly = oci_parse($conn, $assembly_sql); $stid_welding = oci_parse($conn, $welding_sql); $stid_drilling = oci_parse($conn, $drilling_sql); $stid_finishing = oci_parse($conn, $finishing_sql); // The defines MUST be done before executing oci_define_by_name($stid, 'QTY', $qty); oci_execute($stid); oci_define_by_name($stid_cutting, 'CUTTING', $cutting); oci_execute($stid_cutting); oci_define_by_name($stid_assembly, 'ASSEMBLY', $assembly); oci_execute($stid_assembly); oci_define_by_name($stid_welding, 'WELDING', $welding); oci_execute($stid_welding); oci_define_by_name($stid_drilling, 'DRILLING', $drilling); oci_execute($stid_drilling); oci_define_by_name($stid_finishing, 'FINISHING', $finishing); oci_execute($stid_finishing); // Each fetch populates the previously defined variables with the next row's data oci_fetch($stid); oci_fetch($stid_cutting); oci_fetch($stid_assembly); oci_fetch($stid_welding); oci_fetch($stid_drilling); oci_fetch($stid_finishing); //echo quantity to the screen echo "<b><font size='10'>".$qty."</font></b></br>"; if ($cutting == $qty){ echo "<p><b><font color='#FF8566' size='5'>CUTTING COMPLETED</font></b></p>"; } else { $maxcutting = $qty - $cutting; echo "<input id='cutting' name='cutting' type='number' min = '0' max = '$maxcutting' placeholder='CUTTING PROGRESS TODAY' class='input'/>"; } if ($assembly == $qty){ echo "<p><b><font color='#FF8566' size='5'>ASSEMBLY COMPLETED</font></b></p>"; } else { $maxassembly = $qty - $assembly; echo "<input id='assembly' name='assembly' type='number' min = '0' max = '$maxassembly' placeholder='ASSEMBLY PROGRESS TODAY' class='input'/>"; } if ($welding == $qty){ echo "<p><b><font color='#FF8566' size='5'>WELDING COMPLETED</font></b></p>"; } else { $maxwelding = $qty - $welding; echo "<input id='welding' name='welding' type='number' min = '0' max = '$maxwelding' placeholder='WELDING PROGRESS TODAY' class='input'/>"; } if ($drilling == $qty){ echo "<p><b><font color='#FF8566' size='5'>DRILLING COMPLETED</font></b></p>"; } else { $maxdrilling = $qty - $drilling; echo "<input id='drilling' name='drilling' type='number' min = '0' max = '$maxdrilling' placeholder='DRILLING PROGRESS TODAY' class='input'/>"; } if ($finishing == $qty){ echo "<p><b><font color='#FF8566' size='5'>FINISHING COMPLETED</font></b></p>"; } else { $maxfinishing = $qty - $finishing; echo "<input id='finishing' name='finishing' type='number' min = '0' max = '$maxfinishing' placeholder='FINISHING PROGRESS TODAY' class='input'/>"; } echo '<section></br></br></br>'; echo ' <input type="submit" value="SUBMIT PROGRESS" class="button red" />'; echo ' <input type="reset" value="RESET FIELDS" class="button" /></br>'; echo ' <input type="button" value="GO TO PAINTING" name="paint" class="button green" /></section>'; if (isset($_POST['paint'])){ echo 'GO TO THE NEXT PAGE'; } if (isset($_POST['submit'])){ echo 'DO SUBMISSION TO THE DATABASE HERE'; } die;} ?> <!-- HTML CODE --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <title> Update Fabrication Progress</title> <link type="text/css" rel="stylesheet" href="../css/goldenform/golden-forms.css"/> <link type="text/css" rel="stylesheet" href="../css/goldenform/font-awesome.min.css"/> <script type="text/javascript"> function OnSelectionChange (select) { var selectedOption = select.options[select.selectedIndex]; //some ajax checkpoint //alert ("The selected option is " + selectedOption.value); jQuery.ajax({ url: location.href, data: {'hm':selectedOption.value, 'ajax':1}, type: "POST", success: function( data ) { jQuery("#lbl_qty").html(data);//PRINT QTY TO THE SCREEN } }); //some ajax checkpoint //alert('after ajax'); } </script> <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> </head> <body class="bg-wooden"> <div class="gforms"> <div class="golden-forms wrapper"> <form> <div class="form-title"> <h2>FABRICATION UPDATE</h2> </div><!-- end .form-title section --> <div class="form-enclose"> <div class="form-section"> <fieldset> <legend>&nbsp Select HEADMARK and the details will be shown <span class="bubble blue">1</span></legend> <section> <div class="row"> <div class="col4 first"> <label for="headmark" class="lbl-text tleft">HEADMARK :</label> </div><!-- end .col4 section --> <div class="col8 last"> <!-- POPULATED DROPDOWN LIST FROM THE DB --> <label for="headmark" class="lbl-ui select"> <?php $sql_hm_comp = 'SELECT HEAD_MARK FROM FABRICATION'; $result = oci_parse($conn, $sql_hm_comp); oci_execute($result); echo '<SELECT name="headmark" id="headmark" onchange="OnSelectionChange(this)">'.'<br>'; echo '<OPTION VALUE=" ">'."".'</OPTION>'; while($row = oci_fetch_array($result,OCI_ASSOC)){ $HM = $row ['HEAD_MARK']; echo "<OPTION VALUE='$HM'>$HM</OPTION>"; } echo '</SELECT>'; ?> </label> </div> </div> </section><!-- END OF DROPDOWN LIST --> <section> <div class="row"> <div class="col4 first"> <label for="lnames" class="lbl-text tleft">Total Quantity:</label> </div> <div class="col8 last"> <!-- VALUE PASSED FROM AJAX PROCESSING --> <label id='lbl_qty' class='lbl-ui'><font size='3'></font></label> </div> </div> </section> </div> </div> <div class="form-buttons"> </div> </form> </div> </div> <div></div> <div></div> </body> </html>
  20. Okay so i have a file that i need some php variables from. This is the code that i am using. please help ! This is the ajax that i am trying to use to get the variable and then set it to a php variable. $.ajax({ url : 'pagination_data.php?page=1', type : 'POST', data : data, dataType : 'json', success : function (result) { var k=result; <?php $next ?>=var k; }, error : function () { alert("error"); } }); Now here i am setting the varialbes in the other file. $next = $page+1; $prev = $page-1; echo json_encode($next); echo json_encode($prev); and this is where i need the variables... <?php echo "<div class='controls' id='$prev'></div><div class='controls' id='$next'>"; ?>
  21. I need help with adding some ajax to my jquery script to pass a php var to a modal. I can open the modal with the bit of jquery below but I am at a lose on how to add any ajax to this jquery script to take the $id from the link to the modal. The jquery I am opening the modal with $(document).ready(function(){ $(".launch-modal").click(function(){ $("#editexpenses").modal({ keyboard: false }); }); }); I am opening the modal with this link to the jquery <a id="<?php $id ?>" title="Edit this item" class="launch-modal" href="#editexpenses">edit</a> The modal <div class="modal fade" id="editexpenses" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="myModalLabel">Modal title</h4> </div> <div class="modal-body"> <?php $id = $_POST['expID']; echo 'id' . $id; var_dump($_POST); ?> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div><!-- /.modal -->
  22. I have question regarding the setup of url for multiple pages. For eg. How does one have a setup like this? http://www.groupon.ca/deals/gatineau_en/Antirouille-Metropolitain/35853918 The setup I have is like this. //Page 1 with posts shown in a specific catagory. www.mysite.ca/posts_cat.php?catagoryId=1 //Page 2 with a single post shown. www.mysite.ca/posts.php?title=this is my post As you can see, my url setup is quite different than Groupon's. I am not sure if it's the correct way to do it; but it does work. The reason I have two different pages for posts are because I have two different css designs. I suppose my question is, is my method ok? And how do I make it so it looks like Groupon's way?
  23. Say my goal is to have posts with user comments with each individual post. And these posts are posted in relavent catagories. This is all done. Works beautifully. Now say my 2nd goal is to use ajax for everytime a user posts a comment in a post, it'll load the comment without refreshing the page. This is where I am having an issue. So say this is my setup. index.php <a href="records.php?title=<?php echo $record_id; ?>"> records.php <head> script type="text/javascript"> $(document).ready(function(){ $(".comment_button").click(function() { var element = $(this); var test = $("#content").val(); var dataString = 'content='+ test; if(test=='') { alert("Please Enter Some Text"); } else { $.ajax({ type: "POST", url: "ajax.php", data: dataString, cache: false, success: function(data){ $('#display').html(data); document.getElementById('content').value=''; } }); } return false; }); }); </script> </head> <body> <form method="post" name="form" action=""> <textarea name="content" id="content" cols="45" rows="5"></textarea> <input type="submit" value="Update" id="v" name="submit" class="comment_button"/> </form> <div id="display" align="left"> <div> </body> ajax.php // need to get id of current post here. Of course this is not the complete code but you get the idea. The queries that insert and the get the records work. The only issue I have is that the 'get' query won't get the current post id. It makes sense since it's in ajax.php and it's processing through the ajax function. If that query was on records.php, yes it will work. So my question is, is there a way around it?
  24. Hi guys, I am trying to delete DB row without page refresh. I am aware of how to delete by passing URL values and I am trying to do the same thing, but with AJAX. $data = mysql_query("SELECT * FROM playlistsongs WHERE PlayList = '$playlistsongid'") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { ?> <?php <table border="1px"> <tr> <td style="width: 100px;"><?php echo "<b>PlaylistSongID:</b> ".$info['PlaylistSongID'];?></td> <td style="width: 100px;"><?php echo "<b>PlayList:</b> ".$info['PlayList'];?></td> <td style="width: 100px;"><?php echo "<b>UserID:</b> ".$info['UserID'];?></td> <td style="width: 100px;"><?php echo "<b>SongUrl:</b> ".$info['SongUrl'];?></td> <td style="width: 100px;"><?php echo "<b>Status:</b> ".$info['Status'];?></td> <td style="width: 100px;"><?php echo "<b>DateCreated:</b> ".$info['DateCreated'];?></td> <td style="width: 100px;"><?php echo "<b>DateModified:</b> ".$info['DateModified'];?></td> <td style="width: 100px;"><?php echo "<b>Artist:</b> ".$info['Artist'];?></td> <td style="width: 100px;"><?php echo "<b>Title:</b> ".$info['Title'];?></td> <td style="width: 100px;"><a data-customer-id="345" class="button remove">Remove</a></td> </td> </tr> </table> And this is my AJAX request: function DeletePlayListItem(){ $.ajax({ 'url': 'processing/delete-playlist-items.php', 'async': false, data: "PlaylistSongID=" + PlaylistSongVarID + "&UserID=" + UserVarID + "&Status=", success: function (response) { var posturl='http://localhost/xampp/websites/Djapp/processing/delete-playlist-items.php' $.getJSON(posturl,function(data){ $.each(data.members, function(i,userdetails){ takeuserid = (userdetails.UserID); title = (userdetails.Title); vote1 = (userdetails.Vote1); }); }); } }); } So my question is, how do I pass the values to the AJAX on click/select? Thank you for your time!
  25. 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
×
×
  • 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.