i am getting XMLHttpRequest cannot load - javascript

i am getting XMLHttpRequest cannot load.so how to remove this error ,please any suggetion for that.
function soapRCA(){
var productServiceUrl = "https://www.ilportaledellautomobilista.it/eai/AreaVeicolo- ws/services/secure/coperturaRC";
var tipoDiVettura = $('#tipoVeicolo').val();
var targaperRCA = $('#targaRCA').val();
var SoaMessage = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'+
'<soapenv:Header>'+
'<wsse:Security soapenv:mustUnderstand="0" soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">'+
'<wsse:UsernameToken wsu:Id="XWSSGID-1253605895203984534550" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">'+
'<wsse:Username>paolo.pelliccione</wsse:Username>'+
'<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">tdlemon900mj</wsse:Password>'+
'</wsse:UsernameToken>'+
'</wsse:Security>'+
'</soapenv:Header>'+
'<soapenv:Body>'+
'<CoperturaRCVeicoloSecureRequest xmlns="http://www.dtt.it/xsd/Veicolo">'+
'<tipoVeicolo>'+tipoDiVettura+'</tipoVeicolo>'+
'<targa>'+targaperRCA+'</targa>'+
'</CoperturaRCVeicoloSecureRequest>'+
'</soapenv:Body>'+
'</soapenv:Envelope>';
$.ajax({
url: productServiceUrl,
type: "GET",
dataType: "xml",
data: SoaMessage,
complete: showResult2,
contentType: "text/xml; charset=\"utf-8\"",
crossDomain: true,
cache: false
});
return false;
}
function showResult2(xmlHttpRequest, status) {
//alert('edew00');
var data = $(xmlHttpRequest.responseXML).find('#listMovimenti tbody');
console.log(data);
//alert('ecco data: '+JSON.stringify(data));
/*var data = (''+response).substring((''+response).indexOf('<form id="ListaCoperturaRCVeicolo"'),(''+response).length);
data = data.substring(0,data.indexOf('</form>'));
$('#targapage #fintoiframe').html(data);
var ris = $('#targapage #fintoiframe').find('#ListaCoperturaRCVeicolo').html();
$('#targapage #risultatorcaEsterna').html(ris); */
}
</script>

Related

How to write pretty URL based from data?

How to write pretty url from these data?
I need something like this https://mywebsite.com/admin/leads/count/data1/data2/data3
Thanks in advance. :)
var x = {data1, data2, data3};
$.ajax({
url: 'https://mywebsite.com/admin/leads/count/',
data: x,
type: 'GET',
contentType: "application/x-www-form-urlencoded",
datatype: "json",
async: false,
success: function(data){
$("#leads_count").val(data);
leadsCtr = data;
}
});
Take url as a string and manipulate it like this
var x = {data1, data2, data3};
var string = 'https://mywebsite.com/admin/leads/count/';
var fstring = string+x.data1+'/'+x.data2+'/'+x.data3;
$.ajax({
url: fstring,
data: x,
type: 'GET',
contentType: "application/x-www-form-urlencoded",
datatype: "json",
async: false,
success: function(data){
$("#leads_count").val(data);
leadsCtr = data;
}
});

how to append multiple files input on formdata

I have to send multiple files using form data but my code is not working can anybody tell me where it is wrong.
$('#fileupload').on('change', function() {
var to_user_id = $(this).data('touserid');
var chat_id = $(this).data('chat_id');
var formData = new FormData();
$.each($('input[type=file]')[0].files, function(i, value) {
formData.append('file[' + i + ']', value.files[0]);
});
//console.log(formData);
formData.append('to_user_id', to_user_id);
formData.append('chat_id', chat_id);
$.ajax({
url: 'upload.php',
type: 'POST',
data: formData,
dataType: 'json',
processData: false,
contentType: false,
cache: false,
success: function(data) {
//console.log(data);
}
})
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form method="post" name="upload_form" id="upload_form" enctype="multipart/form-data" action="upload.php">
<input type="file" name="fileupload[]" id="fileupload" multiple data-touserid="'+to_user_id+'" data-chat_id="'+getdata+'">
</form>
You have to pass the value in the form data
$.each($('input[type=file]')[0].files, function(i, value){
formData.append('file['+i+']', value); // change this to value
});
sample code which I used
$.each($('#upload_screenshot')[0].files,function(key,input){
formData.append('upload_screenshot[]', input);
});
Please implement below script code.
$('#fileupload').on('change', function(){
var to_user_id = $(this).data('touserid');
var chat_id = $(this).data('chat_id');
var form_data = new FormData();
var ins = document.getElementById('fileupload').files.length;
for (var x = 0; x < ins; x++) {
form_data.append("documentfiles[]", document.getElementById('fileupload').files[x]);
}
if(ins > 0)
{
formData.append('to_user_id', to_user_id);
formData.append('chat_id', chat_id);
$.ajax({
url: 'upload.php',,
dataType: 'text',
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function (response) {
},
});
}
else
{
alert("Please choose the file");
}
});
I hope your problem will be resolved.

Something wrong with ajax call, cannot figure out what

Trying to make a simple ajax call but I'm not able to console.log the response.
Navigating to the url in browser gives back data, but still.
I'm not seeing the error alert either, so it should not be failing?
Code:
var $searchBox = $('#search');
var $searchButton = $('#button');
$searchButton.on('click', function(){
var url = "https://en.wikipedia.org/w/api.php?action=opensearch&search="
+ $searchBox.val() + "&format=json&callback=?";
console.log(url);
$.ajax({
type: 'GET',
url: url,
async: false,
dataType: 'json',
success: function(data){
console.log(data);
},
error: function(errorMessage){
alert('Error');
}
});
});
To prevent click default redirection, you can use e.preventDefault() event.
var $searchBox = $('#search');
var $searchButton = $('#button');
$searchButton.on('click', function(e){
e.preventDefault();
var url = "https://en.wikipedia.org/w/api.php?action=opensearch&search="
+ $searchBox.val() + "&format=json&callback=?";
console.log(url);
$.ajax({
type: 'GET',
url: url,
async: false,
dataType: 'json',
success: function(data){
console.log(data);
},
error: function(errorMessage){
alert('Error');
}
});
});

onvif soap message request using jquery

I am trying to communicate with an onvif camera on the browser but have not success so far. Below is the code that i am using to communicate with the onvif camera.
let soapMessage = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">' +
'<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">'+
'<GetSystemDateAndTime xmlns="http://www.onvif.org/ver10/device/wsdl"/>'+
'</s:Body>'+
'</s:Envelope>';
let ipAdd = '192.168.1.100';
let port = 80;
let path = '/onvif/device_service';
let url = `http://${ipAdd}:${port}${path}`;
$.ajax(
{
type : 'POST',
url,
contentType : 'text/xml; charset="utf-8"',
dataType: "xml",
processData: false,
data : soapMessage,
success : processSuccess,
error : processError
});
function processSuccess(data, status, req)
{
console.log( 'SUCCESS' );
}
function processError(data, status, req)
{
console.log( 'ERROR' );
}
i am getting a net::ERR_EMPTY_RESPONSE
what i am doing wrong. Help needed
My working example basing on your question:
var soapMessage = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">' +
'<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">'+
'<GetSystemDateAndTime xmlns="http://www.onvif.org/ver10/device/wsdl"/>'+
'</s:Body>'+
'</s:Envelope>';
var ipAdd = '192.168.2.110';
var port = 80;
var path = '/onvif/device_service';
var wsurl = `http://${ipAdd}:${port}${path}`;
jQuery.support.cors = true;
$.ajax({
type: "POST",
url: wsurl,
crossDomain: true,
processData: false,
data: soapMessage,
success: processSuccess,
error: processError
});
}

How to get json in javascript or ajax

I have json data
how can i get this data using javascript
thanks :)
this is my code
var getJsonData = function(uri,callback){
$.ajax({
type: "GET",
dataType: "jsonp",
url: uri,
jsonpCallback: 'response',
contentType: "application/json",
success: function(json){
console.log(json);
callback(json);
}
});
}
var uri = pbxApi+"/confbridge_participants/conference_participants.json?cid="+circle;
getJsonData(uri, function(res){
}
var uri = pbxApi+"/confbridge_participants/conference_participants.json?cid="+circle;
getJsonData(uri, function(res){
var data = JSON.parse(res);
for(var objectIndex=0; objectIndex < data.length; objectIndex++){
var tempObject = data[objectIndex];
var id = tempObject.id;
var uid = tempObject.uid;
....
var updated_at = tempObject.updated_at;
}
}
you don't need use jsonp to get json data,
var getJsonData = function(uri,callback){
$.ajax({
type: "GET",
dataType: "json",
url: uri,
contentType: "application/json",
success: function(json){
console.log(json);
callback(json);
}
});
}
var uri=pbxApi+"/confbridge_participants/conference_participants.json?cid="+circle;
getJsonData(uri, function(res){
console.log(res
}

Categories

Resources