I'm trying to get some XML file from the net and i need to display that in my html page......
This is how my javascript file looks like:
$(document).ready(function(){
$(".update").append("<ul></ul>");
$.ajax({
type: "GET",
url: "https://www2.informatik.hu-berlin.de/~xing/Lib/Docs/jaxp/docs/tutorial/sax/samples/slideSample01.xml",
dataType: "xml",
success: function(xml){
$(xml).find('slide').each(function(){
var sTitle = $(this).find('title').text();
//var sPublisher = $(this).find('heading').text();
$("<li></li>").html(sTitle + ", " + "sPublisher").appendTo(".update ul");
});
},
error: function() {
alert("An error occurred while processing XML file.");
}
});
});
When i try to run this using this URL the browser gives an error saying "An error occurred while processing XML file"........................
But if i download the XML File and write it as following.... It will run the page without any errors.......
$.ajax({
type: "GET",
url: "data.xml",
dataType: "xml",
...................................
I also tried to use another online XML File same thing happened...... Anyone has an idea how to solve this???
Thank You!!!!!
Related
I'm getting a 403 error while making an AJAX request to a php page of my own website.
This is the error:
"jq.js:663 POST https://playonlineloto.com/backend/cstatus.php 403"
I'm using jQuery to make the request. The code is:
function status() {
var table = document.getElementById("table").value;
var name=document.getElementById("username").innerHTML;
var card=document.getElementById("card").innerHTML;
var dataString = "table=" + table+"&name="+name+"&card="+card;
$.ajax({
type: "POST",
url: "cstatus.php",
data: dataString,
cache: false,
success: function(html) {
if(html=="no"){
}else{
console.log("kicked out");
console.log(html);
var kick = document.getElementById("kick");
kick.style.display="block";
}
}
});
};
and I'm requesting from this url
https://playonlineloto.com/backend/custom-game.php?val=1&table=U7Gh8c7f6&admin=yes
My files have enough permission. Please help me!!
I am trying to get a jQuery var into PHP so I can use it with mysql. I have searched everywhere but nothing seemed to solve it.
I have the following jQuery code:
$('.eventRow').click(function(){
var eventID = this.id;
$.ajax(
{
url: "index.php",
type: "POST",
data: { phpEventId: eventID},
success: function (result) {
console.log('success');
}
});
$('#hiddenBox').html(eventID);
console.log(eventID);
});
If I run this, the ID is shown in both #hiddenBox and in the console.log. The console also says "Succes" from the Ajax.
I am trying to get it in the php file:
$value = $_POST['phpEventId'];
echo "<div class = 'showNumber'>"."Nummer: ".$value."</div>";
It just says: Nummer:
It also gives no error whatsoever.
Thanks for your help!
Try
var eventID = $(this).attr('id');
Where this id comes from in your code ?
Passing it as JSON often gets the results I'm looking for. The server will interpret the JSON object as POST variables:
$.ajax({
url: "index.php",
type: "POST",
data: JSON.stringify({phpEventId: eventID}),
contentType: "application/json; charset=utf-8",
success: function (result) {
console.log(result);
}
});
I am able to upload a spreadsheet (.csv or XLS files), but when checking on the file from Parse.com, it is all empty. I am uploading the file from client side code (not using REST). Do you think that is the problem? This works just fine for a simple image/file upload using a similar code, but fails for csv or xls type file.
Here's the code:
$scope.uploadSpFile = function(fileUpload){
var name = fileUpload.name;
var parseFile = new Parse.File(name, fileUpload.spFile);
var serverUrl = 'https://api.parse.com/1/files/' + fileUpload.name;
var mySpreadsheet = new Parse.Object(fileUpload.className);
$.ajax({
type: "POST",
beforeSend: function(request) {
request.setRequestHeader("X-Parse-Application-Id", parse_app_id);
request.setRequestHeader("X-Parse-REST-API-Key", parse_rest_id);
request.setRequestHeader("Content-Type", fileUpload.spFile.type);
},
url: serverUrl,
data: fileUpload.mySpreadsheet,
processData: false,
contentType: false,
success: function(data) {
mySpreadsheet.set({filetitle: data.name});
mySpreadsheet.set({fileurl: data.url});
mySpreadsheet.set({name: name});
mySpreadsheet.set({fileCategory: ''});
mySpreadsheet.set({file: {"name": data.name,"url": data.url,"__type": "File"}});
mySpreadsheet.save();
console.log('file saved!');
},
error: function(data) {
var obj = jQuery.parseJSON(data);
console.log('error: ' + obj.error);
outputMsg = obj.error;
}
});
}
});
when i use a similar code to upload an image, I can access the file on my parse page, but xls or csv files turn out to be empty (actually, in XLS case, an error pops out as the format is corrupted).
Anyone has any idea how to fix this issue?
thanks for the help.
I'm trying to replicate the WhateverOrigin service, seen here:
http://stackshare-importer.herokuapp.com/get_website?url=http://firebase.com
However when I try to run it on my browser this code which worked perfectly on WhateverOrigin no longer works with my dummy service:
$.getJSON("http://stackshare-importer.herokuapp.com/get_website?url=" + import_url + "&callback=?", function(data) {
console.log(data);
});
Uncaught SyntaxError: Unexpected token <
I just want to work with the html source string, how can I achieve this?
Edit:
Also tried this and get the same result:
$.ajax({
url: "http://stackshare-importer.herokuapp.com/get_website?url=" + import_url + "&callback=?",
jsonp: "callback",
dataType: 'jsonp',
success: function(response) {
console.log(data);
}
});
Sites like WhateverOrigin and AnyOrigin get the page you want and convert it to a JSON/JSONP object, which allows it to be used cross-origin.
If you are trying to replicate what those websites are doing, you will need to create a PHP script which gets the page as a variable and then converts it to JSON and outputs it in a JSONP object.
Change the PHP on your page "get_website" to:
<?php
$page = file_get_contents($_GET['url']);
echo 'jsonCallback({"html":'.json_encode($page, JSON_HEX_TAG|JSON_HEX_AMP|JSON_HEX_QUOT).'});';
?>
Then use this HTML/JS on any site to output the JSON:
<div class="stuffhere"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$("document").ready(function () {
$.ajax({
type: 'GET',
url: 'http://stackshare-importer.herokuapp.com/get_website?url=http://firebase.com',
jsonpCallback: 'jsonCallback',
contentType: "application/json",
dataType: 'jsonp',
success: function(json) {
alert(json.html);
$("div.stuffhere").html(json.html);
}
});
});
</script>
..and it will work!
I am trying to get JSON data from Yahoo's Finance API.
$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20yahoo.finance.quotes%20WHERE%20symbol%3D%27WRC%27&format=json&diagnostics=true&env=store://datatables.org/alltableswithkeys&callback", function(data) {
// I am parsing JSON string using data here
});
Problem is when when stock is close, I need to show last trade values. I found a link which returns values as a CSV file. So I need to download it and parse it with jQuery.
This is what I have done so far:
$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20yahoo.finance.quotes%20WHERE%20symbol%3D%27WRC%27&format=json&diagnostics=true&env=store://datatables.org/alltableswithkeys&callback", function(data) {
if(data.query.results.quote.DaysLow == null && data.query.results.quote.DaysHigh == null){
//When stock is closed this section works
var date = data.query.results.quote.LastTradeDate;
var datesplit = date.split('/');
$.ajax({
type: "GET",
url: "http://ichart.finance.yahoo.com/table.csv?s=WRC&a="+ datesplit[1] +"&b="+ datesplit[0] + "&c="+ datesplit[2] +"&d="+ datesplit[1] +"&e="+ datesplit[0] +"&f="+ datesplit[2] +"&g=d&ignore=.csv",
dataType: "text",
success: function(data) {
console.log(data);
}
});
}
else{
//When stock is not closed this section works
//There is no problem in this section
}
});
This is the error message I get:
XMLHttpRequest cannot load
http://ichart.finance.yahoo.com/table.csv?s=WRC&a=18&b=9&c=2012&d=18&e=9&f=2012&g=d&ignore=.csv.
Origin null is not allowed by Access-Control-Allow-Origin.
Can you please help me for downloading CSV file?
I think there is no need of ajax you can simply call it like
document.location.href = "http://ichart.finance.yahoo.com/table.csv?s=WRC&a="+ datesplit[1] +"&b="+ datesplit[0] + "&c="+ datesplit[2] +"&d="+ datesplit[1] +"&e="+ datesplit[0] +"&f="+ datesplit[2] +"&g=d&ignore=.csv";
It will not reload page
You can do it by using any server side script
eg :-
$.ajax({
type: "GET",
url: "your-server-side-file.php",
dataType: "text",
success: function(data) {
console.log(data);
}
});
and in that server file your-server-side-file.php process the csv file parse the value. return with your own format.
For example php csv file parsing http://php.net/manual/en/function.fgetcsv.php