3

I'm trying to send a post request using jQuery in my .php file. I have a button that on click runs the JS method and then after validation sends the requests.

Anyway, it doesn't work yet because it throws error "$.ajax is not a function". When I'm on the site I can see in the sources that I have imported two jQuery files (the second one from bootstrap which doesn't contain ajax calls). So I started wondering about jQuery.noConflict() function.

I implemented the call as here is described.

var jq = jQuery.noConflict();
jq.ajax({
    type: 'POST',
    url: 'order.php'
});

Still without any result. Same error - only changed to jq.ajax is not a function.

I got this line in my index.php header section and below that bootstrap. Switching them doesn't change anything.

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

If it is important: I have index.php file which contains this header. Then in the body section, I'm switching to subpages based on the $_GET PHP function, redirecting to the parent parentorder.php file, then if the user is logged I'm including order.php file which displays additional content and should handle orders.

So I was thinking maybe there is some error with my includes or so but if I can see in the section 'sources' jQuery file that should mean it is imported properly, right?

Jainil
  • 1,488
  • 1
  • 21
  • 26
sobczi
  • 121
  • 7
  • 6
    The `$.ajax is not a function` error is normally because you're using the slim branch of jQuery, not the full version. Remove that slim reference and use only a single copy of `jquery-3.4.1.min.js` – Rory McCrossan Nov 12 '19 at 18:36
  • Wow! I had in the bottom of the page second reference to jquery-slim, didn't seen that before! Thank you! I was thinking that bootstrap is including this somehow on his own. – sobczi Nov 12 '19 at 18:42

0 Answers0