JavaScript How to send Ajax request in pug template? send ajax request javascript,send ajax request jquery,send ajax

I would like to send Ajax request in pug template file.

form#payment-form()
  section
    label(for="amount")
      input#amount(name="amount" type="tel" min="1" placeholder="Amount"                         value="10")
script(src="scripts/jquery.js")
script.
  (function () {
    var amount = $('#amount').val();
     $.ajax({
      type: "POST",
      url: "/posturl",
      data: {'amount':amount},
      success: function(){},
      dataType: 'json'
    });
  })()

But it doesn't work, how to do it? I want to know how to send ajax request in embeded javascript of pug file

Answer:1

To me there seems to be two issues

  1. You have put unnecessary tabs in your function under (function (){
  2. You need to use document.ready to ensure that HTML content is ready. You can avoid this if you don't really care for DOM once you have the response

check a working example below

doctype html
html
  head
    script(src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js')
    script.
      $(document).ready(function(){
      $.ajax({url: "demo_test.txt", success: function(result){
      $("#div1").html(result);
      }});
      });
  body
    #div1
      h2 Let jQuery AJAX Change This Text
Answer:2

I installed gulp and everything seems fine except for this error when running the gulp command. I get Error: You need to have Ruby and Compass installed and in your system PATH for this task to work. ...

I installed gulp and everything seems fine except for this error when running the gulp command. I get Error: You need to have Ruby and Compass installed and in your system PATH for this task to work. ...

  1. gulp cannot find module
  2. gulp cannot get /
  3. gulp canine
  4. gulp cannot find module 'browser-sync'
  5. gulp cannot find module '@babel/core'
  6. gulp cannot find module 'gulp-sass'
  7. gulp cannot find module 'del'
  8. guelph canada
  9. gulp cannot find module 'internal/util/types'
  10. gulp cannot find module '@microsoft/sp-build-web'
  11. gulp cannot find module 'jshint/src/cli'
  12. gulp cannot find module 'orchestrator'
  13. gulp cannot find module 'babel-preset-es2015'
  14. gulp cancel task
  15. gulp cannot find module 'laravel-elixir'

I am wondering if it is possible to make div adjust to height of screen view. What I want to achieve, is to make the first div always adapt to resolution and push everything beneath off screen. That ...

I am wondering if it is possible to make div adjust to height of screen view. What I want to achieve, is to make the first div always adapt to resolution and push everything beneath off screen. That ...

  1. height screen resolution

I have a div contenteditable in my web page. When you type some text inside the div contenteditable, the text is reproduced in a hidden textarea for the post treatment (form method="post" action="..."...

I have a div contenteditable in my web page. When you type some text inside the div contenteditable, the text is reproduced in a hidden textarea for the post treatment (form method="post" action="..."...

  1. js-beautify preserve newlines

Is it possible to include the users' timezone if I want to send a push notification containing a datetime? Parse.Push.send({ where: query, // Set our Installation query data: { type: ...

Is it possible to include the users' timezone if I want to send a push notification containing a datetime? Parse.Push.send({ where: query, // Set our Installation query data: { type: ...

  1. parse push notification android
  2. parse push notification ios
  3. parse push notification android example
  4. parse push notification
  5. parse push notification swift
  6. parse push notification adapter
  7. parse push notification github
  8. parse push notification icon android
  9. parse push notification action
  10. parse push notification configuration
  11. parse push notifications web
  12. parse server push notification
  13. ios parse push notification payload
  14. parse send push notification
  15. parse javascript push notification
  16. parse server push notifications android
  17. parse server push notifications ios
  18. ionic parse push notifications
  19. parse cloud code send push notification
  20. how to use parse push notification