Jump to content

maxxd

Gurus
  • Posts

    1,698
  • Joined

  • Last visited

  • Days Won

    53

Everything posted by maxxd

  1. The ajax call doesn't interact directly with the php - the only time it'll register a failure is when the call itself fails. So if you call a non-existent endpoint or if the server is down, the ajax call will invoke the error method. If however the php can't find the record or there is an error in your code that doesn't halt the execution of said code, there will still be a successful response from the server and the ajax will treat it as a successful response. What typically happens is the php script returns a json-encoded array with a 'success' index that indicates whether or not the php function worked. This is what I meant when I said 'just have php return the status of the call' - add a boolean to the return payload that can tell the javascript if the php failed in a manner that didn't cause a server exception.
  2. Sorry, I was multitasking and therefor distracted earlier (hence my deleted post). I can give you a quick example using the fetch() api though it's been a while since I've used jquery ajax functions so I couldn't get that working - hopefully this'll still give you a nudge in the right direction. Unsolicited opinion; it's worth looking into fetch() or axios() if you want to move beyond jquery. I find them both simpler to use and easier to read (especially axios). Having said that, there's nothing wrong with jquery but it's not something I personally have seen used for new development in a while. html: <form action="" id="my-form"> <input type="text" name="test-1" id="test-1"> <input type="text" name="test-2" id="test-2"> <input type="submit" value="Click me"> </form> javascript: let frm = document.getElementById('my-form'); frm.onsubmit = e => { e.preventDefault(); let dt = new FormData(e.target); dt.append('new-value', 'test-3'); let ret = fetch('/jstest2-handle.php', { method: 'post', body: dt }).then(d => { return d.text(); }).then(ret => { console.log(ret); }); } jtest2-handle.php: print(json_encode([ 'var1' => 'return1', 'var2' => 'return2', 'varPost1' => $_POST['test-1'], 'varPost2' => $_POST['test-2'], 'varPost3' => $_POST['new-value'] ])); The console.log() output is this: {"var1":"return1","var2":"return2","varPost1":"test1","varPost2":"test2","varPost3":"test-3"} Obviously I put 'test1' into the `test-1` input, and 'test2' into the `test-2` input.
  3. *DELETED*
  4. Yes - ajax will load the specified php script and it will execute. In your sample code, you're not passing a variable named 'submit', so your php code won't run. It's been a bit since I've used jQuery, but it should be a simple case of collecting the data and sending it in the second parameter of the $.post() method from the javascript. The php will receive the data and any output will be returned to the calling script.
  5. If all the code is yours, just have php return the status of the call. If you're interfacing with a third party API, check your developer tool's network tab. You can see the request being sent and chances are the third party sends a response packet. Either way, best bet is to console.log the ajax response.
  6. In most CSS setups, there's a containing div set with 'overflow: hidden' and an animated height - this then reveals the contents of any nested elements. AFAIR jQuery affects the height of not only the containing div, but the nested elements. So it makes sense that there's a difference in appearance - I'm not aware of a CSS-only solution that will do the "un-squishing" you can (as I recall, will) see with jQuery. That having been said, whether you're concerned about injection vulnerabilities or server downtime using a CDN-based version of jQuery, you pretty much don't need to be. As long as you're using (for instance) jsDeliver, cdnjs, or code.jquery.com, you can be reasonably assured that it's safe and reliable. And of course if the idea still bothers you, just download the file and include it directly from your own server. Funny aside - I didn't realize jQuery was still under active development until last week when I saw the v4 beta announcement.
  7. In addition to that, you're using $curPageName all over that code, but I don't see where it's defined outside the if conditional. This means that if $_GET['id'] is not set, neither is $curPageName.
  8. If you're on WordPress I'm going to assume you're using WooCommerce for your transactions. It's been a long time since I've used WP or WC, but I'd be surprised if there wasn't an affiliate program extension. I'd look in the WooCommerce marketplace.
  9. $_SERVER['DOCUMENT_ROOT'].'/inc/header.php'; This will work from any sub-directory, as long as the `inc` directory is at the top level of the file hierarchy.
  10. It's been a long time since I've touched WP, but as I remember it right now you're using a global action - it fires on every page. You can either override the specific templates you're looking to add the form to, or check the template name and conditionally output the form.
  11. I'm on Windows 11 and use WSL2 with Ubuntu 20 LTS - works like a charm. Create your site files in the Ubuntu filesystem and it's hella fast, as well. You could also use Docker if WSL2 doesn't work for you.
  12. You're still setting the $key variable inside a conditional. $key = array_search('a+', $bloodType_list); Don't wrap it in a conditional, just make the assignment a statement. Then check the value of the variable against false (which you are currently doing).
  13. Don't try to assign and compare on the same line; it makes things complicated. Assign the array_search result to $key on it's own line, absolutely compare $key to false. If $key is not false, unset the value at index $key.
  14. Any chance you'd explain how it got fixed in case someone comes across this thread and it may help them?
  15. It's hard to read given the formatting (I assume that's a problem with the forum otherwise most of your code is commented out), but it looks like you're using a date range for the select queries but not looping through the results of the queries. You're printing the information out inside the loop, but only checking the [0] index in both results.
  16. OK, that looks like legitimate code that should work. What's the problem? What errors are you getting? What do you expect to happen, and what's actually happening? Help us help you.
  17. I agree with the 3 inserts method and highly recommend using a transaction. That way if any of the child inserts fail, the parent inserts are rolled back and there aren't any abandoned and potentially problematic parent records.
  18. According to https://caniuse.com/?search=webp safari has supported webp since November 2020 on Big Sur or above. I can't remember what OsX is on now, but again according to caniuse.com it's been completely supported since September 2022. You're probably OK to assume it's safe to use.
  19. You're not populating the studentSelect form element at any point. You create it in the HTML, assign an event listener to the change event, but never actually put anything in there to change.
  20. Mailgun and Sendgrid are pretty good, yeah. Although - in my experience - even they sometimes seem like they're guessing at statistics. Edit: I realize I sound like I'm shitting on email services; I'm not. They're far more reliable than home-grown or most native solutions, but I remember a campaign I worked that reported like 80% open rate and 65% click-through on Sendgrid and I was like "uhhh ... nah, dude. I don't think so."
  21. Don't worry about aggregating the data on the way into the database; do that while you're selecting the data from the database. All SQL dialects are built to handle large amounts of data efficiently by default (obviously the table schema design helps, but the point stands) so don't exclude data you may be able to use later.
  22. I wouldn't use php's native mail function to be honest. PHPMailer is easier, more robust, and more reliable as both requinix and ginerjm have pointed out. That having been said, if your project requires mail stats you may be better off looking into a service. MailChimp has an API that doesn't completely suck and ConstantContact has an API - both of them have methods in place to gather interaction stats, though honestly even those can be dubious at times.
  23. OP - check the developer's tools in your browser. I'll bet requinix is right that the file path is off and the css file is not being found - if that's the case the network tab should show a 404 for your CSS file.
  24. I'm not sure what the latest code is part of (looks like a framework component?), tbh. So the obvious things to check are is the code wrapped in a document.ready or document.loaded check, and is the PHP actually outputting what you're expecting it to output?
  25. Is the modal loaded without any elements at page lead, then the elements are built dynamically when a button is clicked? Or is the modal dynamically built (then hidden) on page load?
×
×
  • 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.