xmlhttprequest

Posting JSON object through WinJS.XHR

亡梦爱人 提交于 2019-12-14 02:43:37
问题 I'm having abit of problems posting data from WinJS.xhr to a PHP script. "obj" is a stringified JSON object WinJS.xhr({ type: "POST", url: dataUrl, headers: { "Content-type": "application/x-www-form-urlencoded" }, data: obj, }) However the $_POST variable is always empty. I've tried changing content-types, and escaping the object but no luck :( 回答1: Your content-type when posting json should typically be application/json Secondly make sure you 'stringify' your json object. Based on: Post JSON

Cross-domain XHR to https address (SSL) fails in Firefox (works in Chrome)

笑着哭i 提交于 2019-12-14 02:37:48
问题 I'm trying to make a cross-domain XHR to a secure domain. I used the following code to do so: this.post = function (url, data) { var xmlhttp=new XMLHttpRequest(); xmlhttp.open("POST",url,true); xmlhttp.withCredentials=true; xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8"); xmlhttp.send(data); } I use this function with url-encoded string data and https://mydomainx.com/request as url. I tested it on Chrome and Firefox, with Chrome Dev Tools / Firebug

Deleting Sharepoint Files using XMLHTTP

半世苍凉 提交于 2019-12-14 01:30:30
问题 Following on from this excellent piece of work, here: Batch copy files to SharePoint site I can now upload my zipped files to Sharepoint with a click of a button. My problem is now thus: How do I delete the files I upload using the same method? I've amended the code slightly to save different files to different SharePoint folders. Sample below: Public Sub CopyToSharePoint() Dim xmlhttp Dim sharepointUrl Dim sharepointFolder Dim sharepointFileName Dim LstrFileName, strFilePath, strMonthYear,

Timeout feature in the axios library is not working

廉价感情. 提交于 2019-12-14 00:28:39
问题 I have set axios.defaults.timeout = 1000; I stopped the server that provides me with the APIs. But it takes more than 1s to timeout after sending a request. This is how my request looks: import axios from 'axios'; axios.defaults.timeout = 1000; return axios.post(`${ROOT_URL}/login/${role}`, creds).then((response) => { console.log(response); if(response.status === 200) { // If login was successful, set the token in local storage localStorage.setItem(`${role}_log_toks`, JSON.stringify(response

Content-Type header not being set with Angular $http

故事扮演 提交于 2019-12-14 00:19:00
问题 I'm trying to make a cross-origin POST request using Angular $http with the following code. //I've tried setting and removing these http config options $http.defaults.useXDomain = true; delete $http.defaults.headers.common['X-Requested-With']; $http.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded'; //Basic request, with some private headers removed return $http({ method: 'POST', //withCredentials:true, headers: { 'Content-Type': 'application/x-www-form-urlencoded;

retrieving data from a database using ajax without requesting every x seconds

痴心易碎 提交于 2019-12-13 23:31:12
问题 I have been reading up on how to use XMLHTTPRequests to grab data from a database via JavaScript . However, I have noticed that every single one of these "tutorials" use an interval to retrieve data every x seconds, and it seems like this would be extremely taxing (and unnecessary ) on the server; especially considering sometimes these queries would return nothing at all. So, how do websites such as Facebook and Twitter do it? Because something like this (I'm using jQuery for simplicity):

Aborting previous XMLHttpRequest

有些话、适合烂在心里 提交于 2019-12-13 23:04:33
问题 I have a search box and I want to display search results while typing instantly; but on fast typing I have problems. JavaScript: function CreateXmlHttp() { var xmlhttp; try { xmlhttp = new XMLHttpRequest(); } catch (e) { try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("your browser doesn't support ajax"); return false; } } } return xmlhttp; } function searchfunc(value) { if (value!='') { var xmlhttp

Returning value to Javascript from PHP called from XMLHttpRequest

巧了我就是萌 提交于 2019-12-13 21:39:36
问题 I am attempting to add an "Upload Image" feature to my AjaxChat window. The upload to the server works great, but now I need to be able to return the tmp_name/location of the file that was uploaded. In my Javascript I have the following (main) code (some setup code has been omitted because it is unnecessary -- The upload works as expected): // Set up request var xhr = new XMLHttpRequest(); // Open connection xhr.open('POST', 'sites/all/modules/ajaxchat/upload.php', true); // Set up handler

HTTP GET to amazon aws from jquery or XMLHttpRequest fails with Origin is not allowed by Access-Control-Allow-Origin

北城余情 提交于 2019-12-13 21:14:45
问题 Having some bad luck with getting amazon AWS security token from jQuery or XMLHttpRequest. When I send a HTTP GET from jQuery or XmlHttpRequest, I get "Origin http:// MY_IP is not allowed by Access-Control-Allow-Origin.", but if I paste the same URL in my browser, it all goes fine. My code: var url_ = "https://sts.amazonaws.com/?Action=GetSessionToken" + "&DurationSeconds=3600" + "&AWSAccessKeyId=" + AccessKeyId + "&Version=2011-06-15" + "&Timestamp=" + encode(timestamp) + "&Signature=" +

xmlhttp.responseText not display text

北城以北 提交于 2019-12-13 20:07:55
问题 I'm having a situation with ajax responseText. The response text from url is well function. But something inside the ajax code goes wrong. It doesn't recognize the response text and add class to the targeted id. Here's the code : <script type="text/javascript"> function updateField(nameValue){ var xmlHttp=null; try{ xmlHttp=new XMLHttpRequest(); } catch (e){ try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("No AJAX!"); return false; } } xmlHttp.onreadystatechange