Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Commit

Permalink
Bug 445008 - Don't explicitly set Content-Length in XHR
Browse files Browse the repository at this point in the history
Chrome complains when you explicitly set a Content-Length when
performing an XHR POST.

Change-Id: I16bb140dd1d8b6acb12e4a7e5fb7339ade7271ee
Signed-off-by: Samuel Padgett <spadgett@us.ibm.com>
  • Loading branch information
Samuel Padgett committed Sep 24, 2014
1 parent e1f7fda commit 18a4e6a
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 117 deletions.
Expand Up @@ -4,13 +4,13 @@
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
*
*
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
*
* Contributors:
*
*
* IBM Corporation - initial API and implementation
*******************************************************************************/
var numParams = 0;
Expand All @@ -32,18 +32,18 @@ function search(baseUrl){
item.text = resp.results[i].title;
item.value = resp.results[i].resource;
if (ie > 0) {
list.add(item);
list.add(item);
} else {
list.add(item, null);
list.add(item, null);
}
}

searchMessage.style.display = 'block';
loadingMessage.style.display = 'none';
}
};
terms = document.getElementById("searchterms").value;
xmlhttp.open("GET", baseUrl + "?searchFor=" + encodeURIComponent(terms), true);
xmlhttp.open("GET", baseUrl + "?searchFor=" + encodeURIComponent(terms), true);
searchMessage.style.display = 'none';
loadingMessage.style.display = 'block';
xmlhttp.send();
Expand All @@ -53,7 +53,7 @@ function search(baseUrl){
function requestParams(baseUrl){
var ie = window.navigator.userAgent.indexOf("MSIE");
table = document.getElementById("inputTable");

//Clear any old parameter rows from the table
if (table.rows.length > 3)
{
Expand Down Expand Up @@ -81,7 +81,7 @@ function requestParams(baseUrl){
}
};
planId = document.getElementById("plan").value;
xmlhttp.open("GET", baseUrl + "?autoPlan=" + encodeURIComponent(planId), true);
xmlhttp.open("GET", baseUrl + "?autoPlan=" + encodeURIComponent(planId), true);

xmlhttp.send();
}
Expand All @@ -97,30 +97,29 @@ function create(baseUrl){
sendResponse(resp["dcterms:title"], resp["rdf:about"]);
}
};
var postData="";

var postData="";
var planId = document.getElementById("plan").value;

if (planId) {
postData += "&planId=" + encodeURIComponent(planId);
}

if (numParams > 0) {

for (var i=0; i < numParams; i++) {
var thisParam = document.getElementById('param'+i);
var thisParamName = thisParam.name;
var thisParamValue = encodeURIComponent(thisParam.value);
if (thisParamValue) {
postData += "&" + thisParamName + "=" + thisParamValue;
}
postData += "&" + thisParamName + "=" + thisParamValue;
}
}

}

xmlhttp.open("POST", baseUrl, true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length",postData.length);
xmlhttp.send(postData);
}

Expand All @@ -133,29 +132,29 @@ function select(){
}

function sendResponse(label, url) {
var oslcResponse = 'oslc-response:{ "oslc:results": [ ' +
' { "oslc:label" : "' + label + '", "rdf:resource" : "' + url + '"} ' +
var oslcResponse = 'oslc-response:{ "oslc:results": [ ' +
' { "oslc:label" : "' + label + '", "rdf:resource" : "' + url + '"} ' +
' ] }';
if (window.location.hash == '#oslc-core-windowName-1.0') {

if (window.location.hash == '#oslc-core-windowName-1.0') {
// Window Name protocol in use
respondWithWindowName(oslcResponse);
} else if (window.location.hash == '#oslc-core-postMessage-1.0') {
// Post Message protocol in use
respondWithPostMessage(oslcResponse);
}
}
}

function sendCancelResponse() {
var oslcResponse = 'oslc-response:{ "oslc:results": [ ]}';
if (window.location.hash == '#oslc-core-windowName-1.0') {

if (window.location.hash == '#oslc-core-windowName-1.0') {
// Window Name protocol in use
respondWithWindowName(oslcResponse);
} else if (window.location.hash == '#oslc-core-postMessage-1.0') {
// Post Message protocol in use
respondWithPostMessage(oslcResponse);
}
}
}


Expand All @@ -168,7 +167,7 @@ function respondWithWindowName(/*string*/ response) {

// Step #5: indicate that user has responded
window.location.href = returnURL;

}

function respondWithPostMessage(/*string*/ response) {
Expand Down
Expand Up @@ -4,13 +4,13 @@
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
*
*
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
*
* Contributors:
*
*
* IBM Corporation - initial API and implementation
*******************************************************************************/

Expand All @@ -31,18 +31,18 @@ function search(baseUrl){
item.text = resp.results[i].title;
item.value = resp.results[i].resource;
if (ie > 0) {
list.add(item);
list.add(item);
} else {
list.add(item, null);
list.add(item, null);
}
}

searchMessage.style.display = 'block';
loadingMessage.style.display = 'none';
}
};
terms = document.getElementById("searchterms").value;
xmlhttp.open("GET", baseUrl + "?searchFor=" + encodeURIComponent(terms), true);
xmlhttp.open("GET", baseUrl + "?searchFor=" + encodeURIComponent(terms), true);
searchMessage.style.display = 'none';
loadingMessage.style.display = 'block';
xmlhttp.send();
Expand All @@ -59,22 +59,21 @@ function create(baseUrl){
sendResponse(resp["dcterms:title"], resp["rdf:about"]);
}
};
var postData="";

var postData="";
var title = document.getElementById("title").value;
var description = document.getElementById("description").value;

if (title) {
postData += "title=" + encodeURIComponent(title);
}

if (description){
postData += "&description=" + encodeURIComponent(description);
}

xmlhttp.open("POST", baseUrl, true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length",postData.length);
xmlhttp.send(postData);
}

Expand All @@ -87,29 +86,29 @@ function select(){
}

function sendResponse(label, url) {
var oslcResponse = 'oslc-response:{ "oslc:results": [ ' +
' { "oslc:label" : "' + label + '", "rdf:resource" : "' + url + '"} ' +
var oslcResponse = 'oslc-response:{ "oslc:results": [ ' +
' { "oslc:label" : "' + label + '", "rdf:resource" : "' + url + '"} ' +
' ] }';
if (window.location.hash == '#oslc-core-windowName-1.0') {

if (window.location.hash == '#oslc-core-windowName-1.0') {
// Window Name protocol in use
respondWithWindowName(oslcResponse);
} else if (window.location.hash == '#oslc-core-postMessage-1.0') {
// Post Message protocol in use
respondWithPostMessage(oslcResponse);
}
}
}

function sendCancelResponse() {
var oslcResponse = 'oslc-response:{ "oslc:results": [ ]}';
if (window.location.hash == '#oslc-core-windowName-1.0') {

if (window.location.hash == '#oslc-core-windowName-1.0') {
// Window Name protocol in use
respondWithWindowName(oslcResponse);
} else if (window.location.hash == '#oslc-core-postMessage-1.0') {
// Post Message protocol in use
respondWithPostMessage(oslcResponse);
}
}
}


Expand All @@ -122,7 +121,7 @@ function respondWithWindowName(/*string*/ response) {

// Step #5: indicate that user has responded
window.location.href = returnURL;

}

function respondWithPostMessage(/*string*/ response) {
Expand Down

0 comments on commit 18a4e6a

Please sign in to comment.