Currently I have a variable called &quot;data&quot; that I assign static JSON data, then push the values to arrays using three variables named rev_date, rev_area &amp; rev_cases, using the following Javascript code; data = [{   &quot;date&quot;: &quot;2020-10-17&quot;,   &quot;areaName&quot;: &quot;Devon&quot;,   &quot;newCasesByPublishDate&quot;: &quot;108&quot; }, {   &quot;date&quot;: &quot;2020-10-16&quot;,   &quot;areaName&quot;: &quot;Devon&quot;,   &quot;newCasesByPublishDate&quot;: &quot;76&quot; }];  let rev_date = []; let rev_area = []; let rev_cases = [];  data.map((item) =&gt; {     rev_date.push(item.date);     rev_area.push(item.areaName);     rev_cases.push(item.newCasesByPublishDate);   });  My question is, there is an api that returns the same data in JSON format, using the following URL -  Is there an easy way using ajax or something else to replace my static &quot;data&quot; variable holding the JSON data, to pull the data dynamically from the URL above?
3403
I need to do an  request in JavaScript. What's the best way to do that?  I need to do this in a Mac OS X dashcode widget.
26387
I have a text file in the root of my web app  and I'd like to load it into a variable in javascript.. in groovy I would do this:  def fileContents = 'http://localhost/foo.txt'.toURL().text; println fileContents;   How can I get a similar result in javascript?
104045
I have a request that returns a JSON object with a single property which is an array.  How can I test if the array is empty?  With jQuery code like:   $.getJSON(             jsonUrl,             function(data) {                 if (data.RoleOwners == [ ]) {                     $('&lt;tr&gt;&lt;td&gt;' + noRoleOwnersText + '&lt;/td&gt;&lt;/tr&gt;').appendTo("#roleOwnersTable tbody");                     return;                 }                 $.each(data.RoleOwners, function(i, roleOwner) {                     var tblRow =                     "&lt;tr&gt;"                     + "&lt;td&gt;" + roleOwner.FirstName + "&lt;/td&gt;"                     + "&lt;td&gt;" + roleOwner.LastName + "&lt;/td&gt;"                     + "&lt;/tr&gt;"                     $(tblRow).appendTo("#roleOwnersTable tbody");                 });   what can I put instead of if(data.RoleOwners == [ ]) to test if the RoleOwners is an empty array?  Thanks, Matt
99745
Is there a way to display previous and current year with dynamic text?    If so, what is the formatting?   I'm using ArcMap 10.0
38310
Given the following classes and controller action method:  public School {   public Int32 ID { get; set; }   publig String Name { get; set; }   public Address Address { get; set; } }  public class Address {   public string Street1 { get; set; }   public string City { get; set; }   public String ZipCode { get; set; }   public String State { get; set; }   public String Country { get; set; } }  [Authorize(Roles = "SchoolEditor")] [AcceptVerbs(HttpVerbs.Post)] public SchoolResponse Edit(Int32 id, FormCollection form) {   School school = GetSchoolFromRepository(id);    UpdateModel(school, form);    return new SchoolResponse() { School = school }; }   And the following form:  &lt;form method="post"&gt;   School: &lt;%= Html.TextBox("Name") %&gt;&lt;br /&gt;   Street: &lt;%= Html.TextBox("Address.Street") %&gt;&lt;br /&gt;   City:  &lt;%= Html.TextBox("Address.City") %&gt;&lt;br /&gt;   Zip Code: &lt;%= Html.TextBox("Address.ZipCode") %&gt;&lt;br /&gt;   Sate: &lt;select id="Address.State"&gt;&lt;/select&gt;&lt;br /&gt;   Country: &lt;select id="Address.Country"&gt;&lt;/select&gt;&lt;br /&gt; &lt;/form&gt;   I am able to update both the School instance and the Address member of the school.  This is quite nice!  Thank you ASP.NET MVC team!  However, how do I use jQuery to select the drop down list so that I can pre-fill it?  I realize that I could do this server side but there will be other dynamic elements on the page that affect the list.  The following is what I have so far, and it does not work as the selectors don't seem to match the IDs:  $(function() {   $.getJSON("/Location/GetCountryList", null, function(data) {     $("#Address.Country").fillSelect(data);   });   $("#Address.Country").change(function() {     $.getJSON("/Location/GetRegionsForCountry", { country: $(this).val() }, function(data) {       $("#Address.State").fillSelect(data);     });   }); });
81188
Just wondering if there is anything built-in to Javascript that can take a Form and return the query parameters, eg: "var1=value&amp;var2=value2&amp;arr[]=foo&amp;arr[]=bar..."  I've been wondering this for years.
101706
While playing with the JSON parser I encountered a use case (described below in detail) for which using JSON.deserialize(JSONResponse, SampleParent.class) method for parsing doesn't work.  Below is the use case:  public class SampleParent{      public String a {get;set;}     public String b {get;set;}     public String c {get;set;}     public String d {get;set;}     public SampleChild test {get;set;}      public SampleChild{            // in response, for this class doesn't know about the fields. in each and            // every response the fields are changing i.e. it is dynamic with no structure     }  }   How to handle such response using JSON.deserialize  and store it in Apex class variable? Actually I want to store such response in String variable.  Response :- 1  {      "a": "Sometext",       "b": "Sometext",        "c": "Sometext",         "d": "Sometext",       "test": {         "Data1": {           "score": 2         },         "Data2": {           "score1": 1         },         "Data3": {           "score1": 2         }       }   }   Response :- 2   {      "a": "Sometext",       "b": "Sometext",        "c": "Sometext",         "d": "Sometext",       "test": {         "Data50": {           "score12": 2         }              } }   Actually I want to store such response in String variable like a = '{ "Data50": {"score12": 2}}'  Can we handle this use case in Salesforce ?    Any pointers on this would be highly appreciated. Thanks in Advance.
16373
How do I pass have a Javascript script request a PHP page and pass data to it? How do I then have the PHP script pass data back to the Javascript script?  client.js:  data = {tohex: 4919, sum: [1, 3, 5]}; // how would this script pass data to server.php and access the response?   server.php:  $tohex = ... ; // How would this be set to data.tohex? $sum = ...; // How would this be set to data.sum? // How would this be sent to client.js? array(base_convert($tohex, 16), array_sum($sum))
48996
I'd like to implement a simple AJAX function locally that allows me to autocomplete node titles of already existing nodes as the user types. To that end, I need the ability to have an API that I can search on node titles. The problem is that when I output raw JSON, it comes surrounded by tags. So, no matter what I do, I keep getting...  &lt;html&gt;     &lt;head&gt;     &lt;/head&gt;     &lt;body&gt;         &lt;pre style="word-wrap: break-word; white-space: pre-wrap;"&gt; {json here}&lt;/pre&gt;     &lt;/body&gt; &lt;/html&gt;   I've tried implementing a custom page template that only outputs content already, that produced the same results. Here is how I am currently doing this, in my module file...  &lt;?php  /**  * Implementation of hook_menu()  */ function content_relation_menu() {     $items = array();     $items['api'] = array(         'title' =&gt; 'Search',         'page callback' =&gt; 'content_relation_get',         'access callback' =&gt; TRUE,         'type' =&gt; MENU_CALLBACK,     );      return $items; }  function content_relation_get($term = '') {     drupal_add_http_header('Content-Type', 'application/javascript; utf-8');     $var = json_encode(         db_query("SELECT nid,title FROM {node} WHERE title LIKE :title LIMIT 5", array(":title" =&gt; $term.'%'))-&gt;fetchAll()     );     echo $var;     exit(0); }   How can I return JUST raw JSON?
119203
Using AMPScript to parse an XML feed. Client is switching to JSON. Is there something similar to  for JSON in AMPScript? I am confined to using the members login area and not an external API application.
87880
I did not find much info on the "response.getReturnValue" function and what it exactly returns. I understand that this is the function that must be used when a Client Side JS controller calls a Server Side action. The returned value must therefore be whatever the server returned.  My question: Is it a JSON? How can I inspect what is there inside, from the Web console?  So far I have been unsuccessful in doing so.  This is my Apex Controller:  public class CurrencyController { @AuraEnabled public static List&lt;CurrencyType&gt; getCurrencies() {     return [SELECT Id, IsoCode, LastModifiedDate FROM CurrencyType ORDER BY createdDate ASC]; } }   This is my JS Controller  ({   doInit: function(component, event, helper) {         var action = component.get('c.getCurrencies');  // Set up the callback var self = this; action.setCallback(this, function(actionResult) {  component.set('v.currencies', actionResult.getReturnValue());     console.log('currency data is:' + actionResult.getReturnValue()); }); $A.enqueueAction(action); } })   But what is logged is this:  currency data is:[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]  There are 34 Currency items in DB and there are understandably 34 items in this array. But what is there inside these objects? Why is there just two [object Object] when I am picking up 3 fields? I tried changing the number of fields and the log never changes.  I understand this is an extremely foolish question but I just am not able to get it. Please excuse my lack of lightning and Javascript knowledge.  Any insight is much appreciated.
13250
In your MODULENAME.module file: $testVariable = 'himanshu'; drupal_add_js(array('MODULENAME' =&gt; array('testvar' =&gt; $testVariable)), array('type' =&gt; 'setting')); drupal_add_js(drupal_get_path('module', 'MODULENAME') . '/MODULENAME.js');  In MODULENAME.js file: (function($) {   Drupal.behaviors.MODULENAME = {     attach: function (context, settings) {       alert(settings.MODULENAME.testvar);     }   }; })(jQuery);  this way you can pass your php variable in drupal javascript file and use the variable :) How can I implement the above in Drupal 8?
58679
i am trying to fetch the date format for the logged-in User in javascript  on visualforce page. Usually I used to get this data by using:      window.UserContext.dateFormat   Expected Output should be: "dd.mm.YYYY"  but this seems to return blank to me on my page. Could I get this from SOQL query somehow or some other util method?
52467
I've generated some JSON and I'm trying to pull it into an object in JavaScript. I keep getting errors. Here's what I have:  var data = '{"count" : 1, "stack" : "sometext\n\n"}'; var dataObj = eval('('+data+')');   This gives me an error:   unterminated string literal   With JSON.parse(data), I see similar error messages: "Unexpected token ↵" in Chrome, and "unterminated string literal" in Firefox and IE.  When I take out the \n after sometext the error goes away in both cases. I can't seem to figure out why the \n makes eval and JSON.parse fail.
43780
I want to pass the java-script value to controller.I am using repeat on VF page.  VF page      &lt;apex:repeat value="{!listAdj}" var="Adj" id="hrs"&gt;       &lt;td&gt;&lt;div class="requiredInput"&gt;&lt;div class="requiredBlock"&gt;&lt;/div&gt;     &lt;apex:inputField id="decimal" value="{!Adj.Hours_Decimal__c}" onchange="setHidden5(this);" &gt;       &lt;/apex:inputField&gt;     &lt;/div&gt;&lt;/td&gt;             &lt;apex:inputField id="hours" value="{!Adj.Hours__c}" /&gt; &lt;apex:inputField id="decimal" value="{!Adj.Hours_Decimal__c}" onchange="setHidden5(this);"/&gt;              &lt;/apex:repeat&gt;   Javascript code  function setHidden5(element){     //split the id of the inputField by ':' and then use the 5th index in the array to exact position of the inputField in the apex:repeat.   var idArray = element.id.split(':');     var hiddenRep1 =document.getElementById("thePage:form:hrs:hrs:"+idArray[4]+":decimal");          var hiddenRep2 = document.getElementById("thePage:form:hrs:hrs:"+idArray[4]+":hours");       if(element.value.length &gt;=1){        document.getElementById("thePage:form:hrs:hrs:"+idArray[4]+":hours").disabled = true; **hiddenRep2.value=hidden1.value;**                }                             }     }   I want to pass the hiddenRep2.value to controller.How to pass that. Hidden2.value is same as hidden1.value + some addition subtraction.i dont know how to pass that value. Can someone me sort out this.  Thanks
23131
What is the best way to convert a JSON code as this:  {      "data" :      {          "field1" : "value1",          "field2" : "value2"     } }   in a Java Map in which one the keys are (field1, field2) and the values for those fields are (value1, value2).  Any ideas? Should I use Json-lib for that? Or better if I write my own parser?
109143
name=Jackson echo $name   This will display Jackson.  name="Jackson" echo $name   This will also display Jackson.   So I assume by putting quotation marks around a variable it is making it a string. What would name=Jackson technically be? Would it also be recognized as a string?