i've got a problem
i want to use a website to do a checkin and checkout on my svn server.
i already got everthing to the point where i can do a checkout using jQuery.
my remaining problem is with the handling of the MERGE process.
within the MERGE svn transmits a chunked response.
but my console just reports Bad Request.
wireshark told m that the Transfer-Encoding is chunked.
but i couldn't set it to chunked. if i set the contentType to chunked the body is chunked not the transfere-encoding.
and jquery.ajax() doesn't provide something as Transfer-Encoding.
trying to put it into the headers didn't work as well...it didn't even show this header
my checkin code:
$.ajax({
type: "OPTIONS",
url: baseURL,
contentType: "text/xml",
data: '<?xml version="1.0" encoding="utf-8" ?><D:options xmlns:D="DAV:"><D:activity-collection-set></D:activity-collection-set></D:options>',
success: function(data1, status, jqxhr){
$.ajax({
type: "POST",
url: baseURL + "/!svn/me",
contentType: "application/vnd.svn-skel",
data: "(create-txn-with-props (svn:txn-user-agent 40 SVN/1.8.9(i686-pc-linux-gnu) serf/1.3.4 svn:log function svn:txn-client-compat-version 5 1.8.9))",
success: function(data2, status, jqxhr){
rev = jqxhr.getResponseHeader('SVN-Txn-Name');
newdata = new XMLSerializer().serializeToString(xmlString["context"]);
hashResult = calcMD5(newdata);
$.ajax({
type: "PUT",
url: baseURL + "/!svn/txr/" + rev + file + ".xml",
headers: {"X-SVN-Version-Name": latestRev, "X-SVN-Base-Fulltext-MD5":hashBase, "X-SVN-Result-Fulltext-MD5": hashResult},
contentType: "text/xml",
data: newdata,
success: function(data3, status, jqxhr){
chunked1 = '<?xml version="1.0" encoding="utf-8"?><D:merge xmlns:D="DAV:"><D:source><D:href>/svn/check/!svn/txn/' + rev + '</D:href></D:source><D:no-auto-merge></D:no-auto-merge><D:no-checkout></D:no-checkout><D:prop><D:checked-in></D:checked-in><D:version-name></D:version-name><D:resourcetype></D:resourcetype><D:creationdate></D:creationdate><D:creator-displayname>';
chunked2 = '</D:creator-displayname></D:prop></D:merge>';
length1 = chunked1.length;
length2 = chunked2.length;
$.ajax({
type: "MERGE",
url: baseURL,
headers: {"X-SVN-Options": "release-locks"},
contentType: "text/xml",
data: length1 + chunked1 + length2 + chunked2,
success: function(data4, status, jqxhr){
alert('file submitted');
},
error: function(jqXHR, textStatus, errorThrown) {
alert(textStatus + ' at MERGE \n' + textStatus);
}
});
},
error: function(jqXHR, textStatus, errorThrown) {
alert(textStatus + ' at PUT\n' + textStatus);
$.ajax({
type: "DELETE",
url: baseURL + "/!svn/txn/" + rev,
success: function(data3, status, jqxhr){
alert('file deleted');
}
});
}
});
},
error: function(jqXHR, textStatus, errorThrown) {
alert(textStatus + ' at POST\n' + textStatus);
}
});
},
error: function(jqXHR, textStatus, errorThrown) {
alert(textStatus + ' at OPTIONS\n' + textStatus);
}
});
EDIT: corrected some mistakes in my code
changed the problemfocus from PUT to MERGE, because i found the problem
the problem was that i transmitted within the "X-SVN-Version-Name" not just the number but 'number', therefore the error "File is out of Date"
set the contentType: "text/xml" and data: chunked1 + chunked2
than everything works fine and svn accepts the file
Related
I want to call a webservice from client side using jquery ajax(with custom headers). And I almost did that. I had set Access-Control-Allow-Origin to force.com and salesforce.com since I'm calling the webservice from salesforce.
When I try to call that API without the custom headers, its getting the response where as when I called with the headers, its not getting the response.
With custom headers
jQuery.ajax({
type: 'POST',
contentType: 'application/x-www-form-urlencoded',
url: 'https://xxx.myclient.com/xxx/xxx/register',
beforeSend: function(xhr) {
xhr.setRequestHeader('orgid', '00D90000000oxxxx');
xhr.setRequestHeader('userid', '00590000001Dxxxxxx');
},
success: function(response) {
alert('success' + JSON.stringify(response));
},
error: function(jqXHR, textStatus) {
alert('jqXHR : ' + JSON.stringify(jqXHR) + ' textStatus : ' + textStatus);
}
});
also tried with
jQuery.ajax({
type: 'POST',
contentType: 'application/x-www-form-urlencoded',
url: 'https://xxx.myclient.com/xxx/xxx/register',
headers: {
"orgid": "00D90000000oxxxx",
"userid": "00590000001Dxxxxxx",
},
success: function(data) {
alert(JSON.stringify(data));
},
error: function(jqXHR, textStatus) {
alert('jqXHR : ' + JSON.stringify(jqXHR) + ' textStatus : ' + textStatus);
}
});
But in both the above cases it is not hitting the server and getting the error message
When I'm not using any headers, then its hitting the server
jQuery.ajax({
type: 'POST',
contentType: 'application/x-www-form-urlencoded',
url: 'https://xxx.myclient.com/xxx/xxx/register',
success: function(response) {
alert('success' + JSON.stringify(response));
},
error: function(jqXHR, textStatus) {
alert('jqXHR : ' + JSON.stringify(jqXHR) + ' textStatus : ' + textStatus);
}
});
Its getting the success response
In response headers it shows that
Access-Control-Allow-Headers: Content-Type
Only content-type is there, Is that the problem?
Whether we need to add our custom headers here?
And when I analysed the network using firefox firebug, it is showing as given below
POST Register (without any headers passed)
OPTIONS Register (with custom headers)
I dont know why this is happening
Can any one help.
Thanks in Advance ..:)
Try adding your custom headers (orgId and userId) in the "Access-Control-Allow-Headers" list of the service you are calling.
I have a field on my database that stores a number of clicks, and want to increment that when I click in a link(<a href="#selecoes" data-identity="31" id="clicks" clicks="0">) of my tag cloud. Note that I get the number of clicks throught my webservice. This is I do so far:
index.html
<div id="tags">
<ul id="tagList">
<li>
<img src='.../>Brasil
</li>
</ul>
main.js
$('#tagList a').live('click', function() {
findByIdSelecoes($(this).data('identity'));
});
function findByIdSelecoes(id) {
console.log('findByIdSelecoes: ' + id);
$.ajax({
type: 'GET',
url: rootURLSelecoes + '/id/' + id,
dataType: "json",
success: function(data){
$('#btnDelete').show();
console.log('findByIdSelecoes success: ' + data.nome);
currentWine = data;
renderDetails(currentWine);
findJogadoresBySelecao(id);
addClick(currentWine);
}
});
}
function addClick(selecao) {
console.log('addClick na seleção: ' + selecao.id_selecao);
$.ajax({
type: 'PUT',
contentType: 'application/json',
url: rootURLSelecoes + '/update/' + selecao.id_selecao,
dataType: "json",
data: formToJSON(),
success: function(data, textStatus, jqXHR){
alert('clicks updated successfully');
},
error: function(jqXHR, textStatus, errorThrown){
alert('updateWine error: ' + textStatus);
}
});
}
function formToJSON() {
return JSON.stringify({
"clicks": ($('#clicks').val())++ // i dont know what i have to do so i try this(don't work)
});
}
I can't update the dataBase when I click the link in the list. The function formToJSON doesn't increment the value in the database.
Try to do this
Make a var number like global, and do this:
function addClick(selecao) {
console.log('addClick na seleção: ' + selecao.id_selecao);
number = parseInt(selecao.clicks,10);
$.ajax({
type: 'PUT',
contentType: 'application/json',
url: rootURLSelecoes + '/update/' + selecao.id_selecao,
dataType: "json",
data: formToJSON(),
success: function(data, textStatus, jqXHR){
alert("Done: " +number);
},
error: function(jqXHR, textStatus, errorThrown){
alert('updateWine error: ' + textStatus);
}
});
}
function`enter code here` formToJSON() {
var ola = parseInt(number,10);
ola = ola +1;
return JSON.stringify({
"clicks": parseInt(ola,10)
});
}
I am doing an Ajax post to a specific page where I either can get an ID as response if everything went as expected or I could get a random html page and a http 400 as response if something went wrong. In the error case I want to open up the entire html page in a new window. I have tried the following but it is not working - it sets the variable data to [object Object] instead of the intended html page.
$.ajax({
type: "POST",
url: postUrl,
data:'message=' + message + '&' + 'title=' + title,
statusCode: {
400:function(data) {
var newWin = open('','windowName','height=300,width=300');
newWin.document.write(data);
},
},
success: function(json) {
alert("Post success");
},
error: function(jqXHR, textStatus, errorThrown) {
alert("Error connecting to page.");
}
});
Specify dataType : 'html' and change the success function variable. Example:
$.ajax({
type: "POST",
dataType: 'html',
url: postUrl,
data:'message=' + message + '&' + 'title=' + title,
statusCode: {
400:function(data) {
var newWin = open('','windowName','height=300,width=300');
newWin.document.write(data);
},
},
success: function(html) {
alert("Post success");
$("#myDiv").html(html);
},
error: function(jqXHR, textStatus, errorThrown) {
alert("Error connecting to page.");
}
});
I have the following ajax call. I want to send out the data in jason format. However I noticed in Fiddler that the data is converted to query string parameters. What I am doing wrong?
$.ajax({
type: "GET",
url: "StatusService.svc/CheckStatus",
data: JSON.stringify({"companyName":"paymins"}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert('ok!');
alter(data.toString());
},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus + ' / ' + errorThrown);
}
});
Change the type of your request to a post.
$.ajax({
type: "POST",
url: "StatusService.svc/CheckStatus",
data: JSON.stringify({"companyName":"paymins"}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert('ok!');
alter(data.toString());
},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus + ' / ' + errorThrown);
}
});
Get cannot contain a body. Use post for that.
I have a page, and i've got a link looking like:
<span>Nordjylland</span>
And in my Javascript file, i've got a function called GetCitiesByRegion(), however, when clicking the link, i get an error, saying that GetCitiesByRegion is not defined?
The function looks like this:
function GetCitiesByRegion(id) {
var params = '{"id":"' + id + '"}'
var request = {
type: "GET",
async: false,
cache: false,
url: "http://" + location.hostname + "/webservices/services.svc/GetCitiesByRegion",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: params,
success: function (result) {
alert("Data Loaded: " + result);
},
error: function (xhr, status, error) {
alert('Fejl ved webservice: error: ' + error);
}
};
$jq.ajax(request);
}