Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

275
Views
How to pass dates as parameters in Ajax url get call?

I have an Ajax call that tries to populate a highchart by calling an api. I am trying to access date values from ViewBag and passing them to the AJAX url, I end up getting an error

jQuery.Deferred exception: Jun is not defined ReferenceError: Jun is not defined

the value from the ViewBag looks like June-2022. The ajax implementation looks like

  $.ajax({
             url: 'api/getProvinceData/'+ @ViewBag.reportinPeriod,
             type: 'GET',
             success: function (data) { }
        });

so the complete api with the values filled up should look like when it gets the value in the ViewBag

 url: 'api/getProvinceData/Jun-2022'

Why am I getting Jun is undefined in Ajax, while I am just accessing the value directly from the ViewBag? Any help is appreciated.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Because you are calling a view it will render it as 'api/getProvinceData/'+ Jun-2020, so the best way to access it is to just have it inside the quotes and not concatenate it so it will be

$.ajax({
             url:  'api/getProvinceData/@ViewBag.reportinPeriod',
             type: 'GET',
             success: function (data) { }
        });

and it will make the api correctly as

 'api/getProvinceData/June-2022
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!