Updated: jQuery to C# – AJAX (with data)

[WebMethod]
public static string testingWebMethod(string name) {

  //Do something with name? 

  string someString = "Woah";

  return someString;
}
var dataToSend = JSON.stringify({
  "name": "foo"
});

$.ajax({
  type: "POST",
  url: "page.aspx/testingWebMethod",
  dataType: "json",
  data: dataToSend,
  contentType: "application/json",
  success: function(response) {
    alert(response.d);
  },
  error: function(err) {
    alert(err.d);
  }
});
Advertisements

Testing Javascript and jQuery array loops

(by axds)

https://jsfiddle.net/s7bn7cfr/

The simple for loop seems to win the speed tests:

let arrLen = test.length; for( let i = 0; i < arrLen; i++ ){  }

Although this method is less DRY as the length of the the array has to be known. JS’s forEach() or jQuery’s $.each() are good alternatives that are dynamic.

The clear worst is the ‘for x in y’ loop. Which has bulky syntax and is slow.