I am using Ajax to post a user subscription data to backend. Based on the information provided by the user server can respond with either 302 (success) or 200 (failure). My Ajax request is below:   $.ajax({                 url : form.action,                 type: "POST",                 data: $('#real-payment-form').serialize(),                 complete: function(xhr,textStatus){                     console.log("complete")                     console.log(xhr.status)                     if (xhr.status = '302'){                      $('#payment-confirmation').modal()}                     }                     else {                         alert('wrong details')}                 })         }   But whatever the server responds with xhr.status is always 200. Can anyone point out what I am doing wrong. How can I pick up the 302 requests using ajax.
120909
What happens if the browser receives a redirect response to an ajax request?
23156
Of course I am aware of Ajax, but the problem with Ajax is that the browser should poll the server frequently to find whether there is new data. This increases server load.  Is there any better method (even using Ajax) other than polling the server frequently?
51615
I developed a chrome extension which extract some data from the user visiting page and I want to transmit them to my database by an AJAX call (my website is a basic wordpress website).  The point is that the ajax response is error 400 and I do not understand where is the problem as I tried to modify my ajax request the best I could.  Here is my AJAX request from content.js  /* Popup clicked */  $('#myOwnCustomToolBar_TT91 #message_to_click form.groupio_form #subscribe').on('click', function(){      chrome.runtime.sendMessage(product_infos);   });    Here is the new background.js file :    chrome.runtime.onMessage.addListener(function(response, sender, sendResponse){          jQuery.ajax({          type:"POST",         url: "https://www.groupio.fr/wp-admin/admin-ajax.php",         contentType: 'json',         dataType: "JSON",         responseType:'json',          data: {             action : "itempricingfunction",             ean : "EANTEST0101010"         },          success:function(data){              alert(data);          },          error: function(errorThrown){             console.log(errorThrown);         }         });  });    Here is my function called itempricingfunction inside the functions.php file of my wordpress theme file  function itempricingfunction(){   $product_ean = (isset($_POST['ean'])) ? htmlentities($_POST['ean']) : NULL; echo json_encode(array('product_ean' =&gt;$product_ean));       exit; }  add_action("wp_ajax_nopriv_itempricingfunction", "itempricingfunction"); add_action("wp_ajax_itempricingfunction", "itempricingfunction");    And finally, when I go to the product page and click on the chrome extension, the response of the ajax call is Error 400.  Thank you very much for your help !
26203
I'm trying to direct a browser to a different page. If I wanted a GET request, I might say  document.location.href = 'http://example.com/q=a';   But the resource I'm trying to access won't respond properly unless I use a POST request. If this were not dynamically generated, I might use the HTML  &lt;form action="http://example.com/" method="POST"&gt;   &lt;input type="hidden" name="q" value="a"&gt; &lt;/form&gt;   Then I would just submit the form from the DOM.  But really I would like JavaScript code that allows me to say  post_to_url('http://example.com/', {'q':'a'});   What's the best cross browser implementation?  Edit   I'm sorry I was not clear. I need a solution that changes the location of the browser, just like submitting a form. If this is possible with , it is not obvious. And this should not be asynchronous, nor use XML, so Ajax is not the answer.
47519
Every time a user posts something containing &lt; or &gt; in a page in my web application, I get this exception thrown.  I don't want to go into the discussion about the smartness of throwing an exception or crashing an entire web application because somebody entered a character in a text box, but I am looking for an elegant way to handle this.  Trapping the exception and showing     An error has occurred please go back and re-type your entire form again, but this time please do not use &lt;   doesn't seem professional enough to me.  Disabling post validation (validateRequest="false") will definitely avoid this error, but it will leave the page vulnerable to a number of attacks.  Ideally: When a post back occurs containing HTML restricted characters, that posted value in the Form collection will be automatically HTML encoded. So the .Text property of my text-box will be something &amp; lt; html &amp; gt;  Is there a way I can do this from a handler?
85816
I need to make an AJAX request from a website to a REST web service hosted in another domain.  Although this is works just fine in Internet Explorer, other browsers such as Mozilla and Google Chrome impose far stricter security restrictions, which prohibit cross-site AJAX requests.  The problem is that I have no control over the domain nor the web server where the site is hosted. This means that my REST web service must run somewhere else, and I can't put in place any redirection mechanism.  Here is the JavaScript code that makes the asynchronous call:  var serviceUrl = "http://myservicedomain"; var payload = "&lt;myRequest&gt;&lt;content&gt;Some content&lt;/content&gt;&lt;/myRequest&gt;"; var request = new XMLHttpRequest(); request.open("POST", serviceUrl, true); // &lt;-- This fails in Mozilla Firefox amongst other browsers request.setRequestHeader("Content-type", "text/xml"); request.send(payload);   How can I have this work in other browsers beside Internet Explorer?
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))
61666
In reading I am not sure if the issue below could have something to do with needing a custom wordpress ajax handler? All of these functions are inside my functions.php file. I have a couple of PHP functions that are supposed to pass information from one to another. The an AJAX call to the final function should produce the final result through that call. Its not happening. My count results in 0 and I am not understanding why. If I replace my query with a static array like [44,55,99,33] then it will pass the values ok. Likewise if I keep the query and simply replace the $id in the query and make it a static id such as '20' then it works. I would think that the id was the issue then and it wasnt pulling properly but it seems to work ok just not pass? function idx(){     global $wpdb, $id;       $getId = $_SERVER['REQUEST_URI'];     $ecp = explode('/', $getId);     if($ecp[3] != ''){         $id = $ecp[3];     }         return $id; } add_action( 'after_setup_theme', 'idx' );  =============================================== function Total_Result(){     global $wpdb;     $id = idx();        /*$resultx = [44,88,59,52];*/ ;      $resultx = $wpdb-&gt;get_results( $wpdb-&gt;prepare(&quot;SELECT * FROM {$wpdb-&gt;prefix}custom_form_submission_conversation as cc LEFT JOIN {$wpdb-&gt;prefix}custom_form_submission as cs on cc.fsid ='$id' WHERE fsid='$id'&quot; ));          $resultxs = array($resultx);          $total_result =  count($resultxs[0]);     echo  $total_result; }  when I var_dump $resultx I get: array(3) { [0]=&gt; object(stdClass)#1256 (36) { [“cid”]=&gt; string(3) “167” [“fsid”]=&gt; string(2) “20” [“specified_date”]=&gt; string(3) “yes” [“price_quote”]=&gt; string(4) “1140” [“posted_by”]=&gt; string(9) “dc_vendor” [“limit_count”]=&gt; string(1) “1” [“read_unread”]=&gt; string(1) “1” [“vendor_response”]=&gt; string(4) “zero” [“date_created”]=&gt; string(19) “2021-04-15 11:39:08” }   [1]=&gt; object(stdClass)#1257 (36) { [“cid”]=&gt; string(3) “186” [“fsid”]=&gt; string(2) “20” [“specified_date”]=&gt; string(3) “Yes” [“price_quote”]=&gt; string(3) “602” [“posted_by”]=&gt; string(8) “customer” [“limit_count”]=&gt; string(1) “1” [“read_unread”]=&gt; string(1) “1” [“vendor_response”]=&gt; string(4) “zero” [“date_created”]=&gt; string(19) “2021-04-15 11:39:08” }   [2]=&gt; object(stdClass)#1258 (36) { [“cid”]=&gt; string(3) “188” [“fsid”]=&gt; string(2) “20” [“specified_date”]=&gt; string(3) “yes” [“price_quote”]=&gt; string(4) “1017” [“posted_by”]=&gt; string(9) “dc_vendor” [“limit_count”]=&gt; string(1) “1” [“read_unread”]=&gt; string(1) “0” [“vendor_response”]=&gt; string(4) “zero” [“date_created”]=&gt; string(19) “2021-04-15 11:39:08” } }   so then I try and pass that data like so: function getvendorresponsestatus() {     global $wpdb; $id = idx();          $total_resultx = Total_Result($id);         die; }  Ive tried with and without the die();. The AJAX call is: setInterval(function(){     var ffiidd = jQuery('#ffiidd').val();     var ajaxurl = &quot;&lt;?php echo admin_url('admin-ajax.php'); ?&gt;&quot;;          jQuery.post(ajaxurl, {         action: &quot;vendorAjaxprog&quot;,         ffiidd: ffiidd     }, function(data) {         console.log(data);         jQuery.post(ajaxurl, {             action: &quot;getvendorresponsestatus&quot;, //&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; this is the action that calls the function             fsid : ffiidd         },         function(datas) {             console.log('+ datas);             jQuery('.cust_vendor_top').html(datas);         });         if(data == 0){}else{             jQuery('.ajaxreload').html(data);                                     }     });               }, 5000);/*==30 seconds==*/  So the question is why wont it pass along the query array information but it passes a basic array or it will pass if I change the id in the query to be static? I know the query is good because of when I var_dumped it, I have results before I get to the Total_Result() function.
89673
I am trying to get  to work within salesforce visualforce pages.  I have a basic vf page from  example, but it does not respopnd, I suspect there may be some "unknown" workaround needed? Does anyone know?  &lt;apex:page standardController="Contact" showHeader="false" sidebar="false" docType="html-5.0"  standardStylesheets="false"&gt;  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="http://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"&gt;&lt;/script&gt;      &lt;div id="the-basics"&gt;   &lt;input class="typeahead" type="text" placeholder="States of USA"/&gt; &lt;/div&gt;  &lt;script&gt;     var substringMatcher = function(strs) {       return function findMatches(q, cb) {         var matches, substrRegex;          // an array that will be populated with substring matches         matches = [];          // regex used to determine if a string contains the substring `q`         substrRegex = new RegExp(q, 'i');          // iterate through the pool of strings and for any string that         // contains the substring `q`, add it to the `matches` array         $.each(strs, function(i, str) {           if (substrRegex.test(str)) {             // the typeahead jQuery plugin expects suggestions to a             // JavaScript object, refer to typeahead docs for more info             matches.push({ value: str });           }         });          cb(matches);       };     };      var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',       'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',       'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',       'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',       'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',       'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',       'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',       'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',       'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'     ];      $('#the-basics .typeahead').typeahead({       hint: true,       highlight: true,       minLength: 1     },     {       name: 'states',       displayKey: 'value',       source: substringMatcher(states)     }); &lt;/script&gt;
104290
In alert I am getting value in data.d.results[0](This is the value that I am getting from other list using rest).Subsystem.Title and also if I use only title column then the value is inserted in the list but when I use a lookup column i.e. Subsystem, then it goes to error function.  $.ajax({         url: "https://sharepoint.com/teams/_api/web/lists/GetByTitle('Features')/Items",         type: "POST",         data:  JSON.stringify({ '__metadata': { 'type': 'SP.Data.FeaturesListItem' },    'Title': data.d.results[0].Title,'Subsystem':data.d.results[0].Subsystem.Title}),         headers: {              "accept": "application/json;odata=verbose",             "content-type":"application/json;odata=verbose",             "X-RequestDigest": $("#__REQUESTDIGEST").val()         },         success: function(d) {alert("Items Inserted!");          //window.location.href=referrer;             },         error: function() {alert("Failed to Insert Items!");} });
2659
What is the most reliable and secure way to determine what page either sent, or called (via AJAX),  the current page.  I don't want to use the $_SERVER['HTTP_REFERER'], because of the (lack of) reliability, and I need the page being called to only come from requests originating on my site. Edit: I am looking to verify that a script that preforms a series of actions is being called from a page on my website.
41510
Attempting to delete questions on the mobile site on iOS causes two notification messages asking me to confirm the deletion, which it shouldn't do.  I haven't really looked into it, but it may just be that the handlers from full.js and mobile.js are both being triggered, as there seems to be the flash of the error dialog indicating something went wrong on the supposed second AJAX request when the response from the first triggers a page reload.  You can see this happening by following the method calls; the mobile view first calls   StackExchange.question.init() -&gt; StackExchange.question.fullInit()   -&gt; StackExchange.vote.init()     -&gt; u()    ...where u() sets a delegated click handler on  $("div.post-menu *[id^='delete-post-'], table.flagged-posts *[id^='delete-post-']")   ...that calls .preventDefault() on the event, but doesn't block other handlers from firing.  It then later calls StackExchange.mobile.init(), which in turn calls the method J() that sets up a similar handler directly on $(".delete-post").  Since both handlers get triggered, there's two confirmation dialogs, and two attempts to delete the post. The extra handler in mobile.js seems unnecessary, so just removing it would appear to be the easy fix to the problem.
39661
I created rest resource plugin in a custom module and need to send some JSON data with the request, and access it in the post function. At the moment my post function does not do anything but return some dummy JSON data so I know it is working.  It seems that whenever I try to pass JSON data with the request, it will give me this error: "Could not denormalize object of type , no supporting normalizer found."  If I then try to get this data using file_get_contents('php://input'), it will give me a 403 forbidden error. But if I try to return the same data that I get from file_get_contents('php://input') from the post function, I get the normalizer error again.  I wasn't able to find much information on even making this REST resource and even less on this issue now, so if anyone has any input I would greatly appreciate it, thanks!
25117
Is it possible to get the progress of an XMLHttpRequest (bytes uploaded, bytes downloaded)?   This would be useful to show a progress bar when the user is uploading a large file. The standard API doesn't seem to support it, but maybe there's some non-standard extension in any of the browsers out there? It seems like a pretty obvious feature to have after all, since the client knows how many bytes were uploaded/downloaded.  note: I'm aware of the "poll the server for progress" alternative (it's what I'm doing right now). the main problem with this (other than the complicated server-side code) is that typically, while uploading a big file, the user's connection is completely hosed, because most ISPs offer poor upstream. So making extra requests is not as responsive as I'd hoped. I was hoping there'd be a way (maybe non-standard) to get this information, which the browser has at all times.
65851
Is there a well-supported, common behavior that I can expect if I do something like this in HTML:  &lt;form method="get" action="/somePage.html?param1=foo&amp;param2=foo"&gt;   &lt;input name="param2"&gt;&lt;/input&gt;   &lt;input name="param3"&gt;&lt;/input&gt; &lt;/form&gt;   Seems like this sort of thing is inherently ridiculous, but I've seen it used here and there and I was wondering what on Earth the expected behavior should be.  Are browsers smart enough to tack on "&amp;param2=whatever&amp;param3=whatever" to the action, or do they just throw in a second question mark?  Or what?  Are there cases where this is actually the right way to do things?
22584
Okay, i'm looking to see if I can get some help in understanding the documentation as laid out here:   I want to refresh a component after a record CRUD operation, the form is being populated from a call to an apex method. The data from this method (called with the @wire service) is then passed into a js function that splits the data into complete and incomplete todo items. Wire service call is:     @wire(getTodos, {     searchKey: '$searchString'   })   sendForSplitting({     error,     data   }) {     if (error) {       this.error = error;     } else if (data) {       this.splitTodos(data);     }   }   In an event handler i want to trigger an update to this dataset, the documentation above seems to reference that I can refresh the apex on a wired method. From that doc:      To refresh a wired method, you must pass the argument the wired method receives (which is the wired value).   To date, I have tried both:     handleCreate() {     return refreshApex(getTodos, {       searchKey: '$searchString'     });   }   and    handleCreate() {     return refreshApex(this.sendForSplitting({       error,       data     }));   }   Both of which throw errors - refresh failed because configuration is not available. How can I make this work? I want to ensure the lists update upon user interaction without having to resort to a manual refresh of the page...
92013
I have a situation where my Ajax call response time could vary from 14ms to 600ms, because of the complexity of a Query they could make.  From my experience Users take for granted those 20-80 ms round trips and expect to have the same speed all the time and everywhere, in reality in my particular project it is impossible.  So I came up with an idea that I could force users always wait for at least some x amount of time before getting results.  Question is: Should I use an average of my own data of response round trip lengths already gathered or should I just use a publicly agreed highest allowed response time to a  Users action?  From what I can remember that was somewhere between 100 - 200 ms I can't remember now.