jquery

Get the closest value for combinations of an array (JS)

谁说胖子不能爱 提交于 2021-02-07 05:28:05
问题 I'm looking for an algorithm that I can use for combining values in array, to get as close as possible to "another value". For instance, the number I want to find out what combination that gives the closes result to is 2.5. And my array is [0.5, 1.0, 1.5, 2.0, 3.0] . The combination in this case would be 2.0+0.5 . 2.7 would yield the same combo (2.5 is the closest), while 3.7 would yield 3.0+0.5 and 7.0 would be 3.0+3.0+1.0 . I've been reading up on different algorithms to create available

How can I return 500 error in JSON format in ASP.NET MVC?

扶醉桌前 提交于 2021-02-07 05:27:05
问题 When ASP.NET MVC throws an exception, it returns a 500 error with response type text/html - which, of course, is invalid JSON. I want to respond to an Ajax request expecting JSON with an error I can receive and display to the user. Is it possible to return JSON with an HTTP status code of 500? When the problem is a missing parameter, the 500 error occurs before the controller is even called - so a controller solution might not work. For example, leaving a required parameter out in a call to

Getting current URL using Jquery

血红的双手。 提交于 2021-02-07 05:17:25
问题 I am very new in javascript and jquery. $.getJSON("idcheck.php?callback=?", { url: /*i want full url to be print*/ }, function(json){ //alert(json.message); }); How do i get current full url on page on after url: in above? Thank you 回答1: This will give you the current url: window.location.pathname edit: $.getJSON("idcheck.php?callback=?", { url: window.location.pathname }, function(json){ //alert(json.message); }); edit 2: Using PHP (found via) <?php function curPageURL() { $pageURL = 'http';

Dynamically change CSS rules in JavaScript or jQuery

岁酱吖の 提交于 2021-02-07 04:46:53
问题 I'm looking for a way to change the CSS rules of my stylesheet imported in the document. So I have an external stylesheet and some class and div attributes inside. I want to change one of the rules with JavaScript or jQuery. Here is an example : .red{ color:red; } So the idea is to do something in JavaScript and the HTML knows that now the color is another color like this: .red{ color:purple; } But I want to have this rule for every element that I add in the future by the way of append. So if

How to trigger an on scroll event without scrolling

老子叫甜甜 提交于 2021-02-07 04:43:11
问题 my Question is, how can i trigger (simulate or something esle) an on scroll event. In my special case I don't want to load all the Conservations in LinkedIn by scolling down all conservations, because there are too many! I do not need a PHP or Javascript solution. Simply using dev-tools at chrome is enough to get my goal. 回答1: Alternatively, you can manually trigger a real scroll event as following: el.dispatchEvent(new CustomEvent('scroll')) Which feels a bit less of a hack (and more

How to send AJAX POST request and play the audio in the response?

人盡茶涼 提交于 2021-02-07 04:16:31
问题 I am building an app where the user can click a button, and it sends data to the server. The server then computes audio based on the data in the request (most likely a POST), and returns a WAV file to the browser. I have already built the part with accepting a post request and responding with the wav file, but I can't figure out how to send the request in JS and to play the response to the user. Also, the playing of the audio must start (almost) as the first byte comes in, as the audio files

How to send AJAX POST request and play the audio in the response?

半城伤御伤魂 提交于 2021-02-07 04:14:13
问题 I am building an app where the user can click a button, and it sends data to the server. The server then computes audio based on the data in the request (most likely a POST), and returns a WAV file to the browser. I have already built the part with accepting a post request and responding with the wav file, but I can't figure out how to send the request in JS and to play the response to the user. Also, the playing of the audio must start (almost) as the first byte comes in, as the audio files

Accessing WebAPI 2 json with DataTables.NET ajax call in MVC application

血红的双手。 提交于 2021-02-07 04:10:54
问题 I have been trying to get DataTables.NET to play nicely with a WebAPI RESTFul service I built and the json being returned does not seem to fit what DataTables is looking for. I have tried the various "server processing" examples along with a few examples I found on the internet like this one, but I don't want to make the WebAPI call dynamic. I want the API to be self documenting so that other applications and other developers can easily also use the API. So far, here is what I have. The JSON

jQuery autocomplete 1.1: Show All Data on focus

坚强是说给别人听的谎言 提交于 2021-02-07 04:09:21
问题 How to make this extension show all data on focus?. I have tried to change minChars to 0 but it only show when the input double clicked. $("#month").autocomplete(months, { minChars: 0, max: 12, autoFill: true, mustMatch: true, matchContains: false, scrollHeight: 220, formatItem: function(data, i, total) { // don't show the current month in the list of values (for whatever reason) if ( data[0] == months[new Date().getMonth()] ) return false; return data[0]; } }); 回答1: You need to bind a focus

jQuery autocomplete 1.1: Show All Data on focus

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-07 04:06:53
问题 How to make this extension show all data on focus?. I have tried to change minChars to 0 but it only show when the input double clicked. $("#month").autocomplete(months, { minChars: 0, max: 12, autoFill: true, mustMatch: true, matchContains: false, scrollHeight: 220, formatItem: function(data, i, total) { // don't show the current month in the list of values (for whatever reason) if ( data[0] == months[new Date().getMonth()] ) return false; return data[0]; } }); 回答1: You need to bind a focus