I am making an ajax call to be used in jquerymobile. It is working fine in my local host , but when i uploaded it in the server, the ajax call returned an error:0
Code:
$(document).on('pageinit', '#Joblist', function(){
if (navigator.onLine)
{
$.ajax({
type: "GET",
url: "http://sample.com/jobs",
headers:{Authorization:authHeader},
dataType: "xml",
success: function(xml)
{
xmlJoblist=xml;
localStorage.removeItem("jobList");
var xmlString = (new XMLSerializer()).serializeToString(xml);
window.localStorage.setItem("jobList", xmlString);
viewJoblist(xml);
},
error: function(result) {
alert("An error occurred while processing XML file.");
console.log("error" + result.status + result.statusText); //result.status:0
}
});
}
});
Related
For example if I have the JS ajax get/post function
function cancelFeeReport() {
var postData = "claimId=" + $("#FeeReport_ClaimID").val() + "&page=#ViewBag.PageNumber";
$.ajax({
type: "POST",
url: '#Url.Action("Cancel", "FeeReports")',
dataType: "json",
async: false,
data: postData,
success: function (result) {
// Do something
},
complete: function () {
// Do nothing for now.
}
});
}
When an error happened in the above JS function. How to identify that cancelFeeReport() threw the error to AJAX global error handler
$(document).ajaxError(function( event, jqxhr, settings, thrownError ) {
alert('Error in ' + <functioname>);
});
The following is my code to send data (formatted XML) but it gives an error. Can anybody tell me what am I doing wrong?
$.ajax({
type: "POST",
url: "XMLFile1.xml",
dataType: "xml",
data: "<event><text>text</text> <date>date</date></event>",
success: function () {
alert("msg sent");
},
error: function() {
alert("error");
}
});
Hi I am a newbie to jQuery , I was just testing a sample SOAP request with the following code , but I am getting error ,Is this because of the server side or the code I have written is wrong? , I mean the syntax .Can anybody help me to check it ?
<script type="text/javascript">
$(document).ready(function () {
$("#btnCallWebService").click(function (event) {
alert("get ready");
var soapMessage ='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">'+
'<soapenv:Header>'+
'<a:Action xmlns:a="http://www.w3.org/2005/08/addressing" soapenv:mustUnderstand="1">'+
'http://xxx/xxxx/xxxx/accountSummary'+
'</a:Action>'+
'</soapenv:Header>'+
'<soapenv:Body xmlns:ws="http://xx.xx.xxx.com/">'+
'<ws:accountSummary/>'+
'</soapenv:Body>'+
'</soapenv:Envelope>';
var url = "http://127.0.0.1/xxx/xxx/xxx/xx?wsdl";
$.support.cors = true;
$.ajax({
type: "POST",
url: url,
crossDomain:true,
dataType: "xml",
processData: false,
contentType: "text/xml; charset=\"utf-8\"",
success: function (soapResponse) {
alert("success: " + soapResponse);
},
error: function (soapResponse) {
alert("Soap" + soapMessage);
alert("Failed: " + soapResponse);
}
});
});
});
</script>
I'm trying to call a php script with a get request and using the data theaddress however the results are showing me the source of the page im calling.
The page im calling is here
Here is my ajax function that will get this page
$( document ).ready(function() {
var address = document.getElementById("address");
$.ajax({
url: '/r10database/checkSystem/ManorWPG.php',
type: 'GET',
data: 'theaddress='+address.value,
cache: false,
success: function(output)
{
alert('success, server says '+output);
}, error: function()
{
alert('Something went wrong, saving system failed');
}
});
});
$( document ).ready(function() {
var address = document.getElementById("address");
$.ajax({
url: '/r10database/checkSystem/ManorWPG.php',
type: 'GET',
data: 'theaddress='+address.value,
cache: false,
success: function(output)
{
alert('success, server says '+output);
}, error: function(error)
{
alert (error); // this is the change from the question
}
});
});
Put the dataType as json with a curly brace
data: {theaddress:address.value},
dataType:'json',
success: function(output)
{
alert('success, server says '+output);
}, error: function(xhr)
{
alert (xhr.status);
}
and get the data in ManorWPG.php as $_GET['theaddress']
** share the xhr.status if failed.
I have this code:
$.ajax({
url: "lang_files/" + window.localStorage.language + ".xml",
dataType: 'xml',
success: function(data) {
var xml_node = $("resources", data);
$("#index_intro").text(xml_node.find('string[name="index_intro"]').text());
},
error: function(data) {
console.log("Error loading XML data");
}
});
It works fine, the .text() is set properly using the information from my XML file, I now want to be able to use the XML file across my application, and not just inside the success call, so I did:
var xml_node;
$.ajax({
url: "lang_files/" + window.localStorage.language + ".xml",
dataType: 'xml',
success: function(data) {
xml_node = $("resources", data);
},
error: function(data) {
console.log("Error loading XML data");
}
});
$("#index_intro").text(xml_node.find('string[name="index_intro"]').text());
This is not working though, I would like to understand why.
This is because ajax is asynchronous so at time you call xml_node, it is still undefined. Try this instead:
$.ajax({
url: "lang_files/" + window.localStorage.language + ".xml",
dataType: 'xml',
success: function(data) {
setIndexIntro($("resources", data));
},
error: function(data) {
console.log("Error loading XML data");
}
});
function setIndexIntro(xml_node)
{
$("#index_intro").text(xml_node.find('string[name="index_intro"]').text());
}