-3

I'm trying to make: $.ajax but it gives me error: $ is not defined.

Question1: But I want to include the jquery on javascript file, it's possible?

Question2: I want to make an asyncronous request GET. It's another way without jquery ajax?

PRVS
  • 1,612
  • 4
  • 38
  • 75
  • 1. Why should `$` be defined? What have you done to define it? – Quentin Apr 02 '16 at 17:40
  • 2. jQuery is a JavaScript library. It is just JavaScript written by other people. Nothing you can do with jQuery can't be done from scratch. – Quentin Apr 02 '16 at 17:41
  • I doesn't define it because I want to define this in javascript... @Quentin – PRVS Apr 02 '16 at 17:41
  • So copy/paste it into your script? – Quentin Apr 02 '16 at 17:47
  • @PRVS when you said "I want to include the jquery on javascript file, it's possible?" this indicated that you don't know how including JavaScript works you can copy and paste your JS directly or use the HTML script tag to import your JS. –  Apr 02 '16 at 17:47
  • I want to include $ like we make in html but in javascript. @Mango – PRVS Apr 02 '16 at 17:48
  • @PRVS when you said "I'm trying to make: $.ajax" I'm assuming that you are trying to make a JavaScript library that implements the features of jQuery, but your also trying to include jQuery? After I edited my comments I noticed that you answerd this question above :D –  Apr 02 '16 at 17:49
  • @PRVS — the JavaScript source code of jQuery – Quentin Apr 02 '16 at 17:49
  • @Quentin it works thanks ;) – PRVS Apr 02 '16 at 17:58

2 Answers2

0

Looks like you haven't included jQuery to main page, from where you're sending a request. (make sure that jquery should be loaded before your js file)

About second question: $.ajax have param named async. I think this is what you need.

Roman Nazarkin
  • 2,209
  • 5
  • 23
  • 44
  • Yes I don't include but I want to include the jquery in javascript and not in html... I can do this? – PRVS Apr 02 '16 at 17:42
  • Try to look here: http://stackoverflow.com/questions/950087/include-a-javascript-file-in-another-javascript-file – Roman Nazarkin Apr 02 '16 at 17:43
  • @RomanNazarkin — Your solution to making an Ajax request without jQuery is to use `$.ajax`? That's a jQuery feature! – Quentin Apr 02 '16 at 17:46
  • @Quentin I know that this is a jQuery feature. I haven't advised to load jQuery with jQuery function. I have mentioned that `$.ajax` have option to make asynchronous calls. – Roman Nazarkin Apr 02 '16 at 17:55
  • ajax is asynchronous by default. Any suggestion of setting it to false is a terrible idea and that is also being deprecated by browsers and will throw warnings – charlietfl Apr 02 '16 at 18:02
  • @charlietfl sometimes option to make non-asynchronous call is helpful. Of course, if you know what are you doing and why. – Roman Nazarkin Apr 02 '16 at 18:07
  • @RomanNazarkin there is no valid use case for needing to do synchronous call and there are numerous ways to work around it. It should never be used as it is a terrible practice. Again...it is deprecated by browsers and will soon disappear – charlietfl Apr 02 '16 at 18:09
  • @charlietfl I'm not a lover of doing thing synchronously in front-end, but if that option was present - it was needed. – Roman Nazarkin Apr 02 '16 at 18:15
  • You aren't listening... it has been deprecated because it was a bad idea. Try it yourself and will see the warning thrown in console not to use it – charlietfl Apr 02 '16 at 18:17
0
  1. You can include jQuery on javascript file. simply add a reference to it.

    <script src="jquery.js"></script>

  2. If you don't want to use jquery ajax function, simply use XMLHttpRequest. here's an example: http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp

Tal
  • 700
  • 4
  • 11