के साथ AJAX-अनुरोध करने में समस्याएं मैं फ़ोनगैप और jQuery के साथ एक साधारण आरएसएस रीडर बनाने की कोशिश कर रहा हूं। मैं इस ट्यूटोरियल का अनुसरण कर रहा हूं: http://visualrinse.com/2008/09/24/how-to-build-a-simple-rss-reader-with-jquery/।फ़ोनगैप एप्लिकेशन
जब मैं अपने ब्राउज़र में कोड आज़माता हूं तो मैं इसे ठीक काम करने में कामयाब रहा हूं। php-file फ़ीड लाता है और इसे आउटपुट करता है जैसा कि मुझे उम्मीद है। लेकिन जब मैं अपने संकलित फोनगैप एप्लिकेशन के भीतर से एक ही फ़ाइल चलाता हूं तो AJAX-request केवल php-file (php-code, निष्पादित परिणाम नहीं) की सामग्री देता है।
मैंने घंटों बिताए हैं और कई ट्यूटोरियल और ट्वीक्स की कोशिश की है। मुझे या तो ऑफलाइन फोनगैप मंचों में कोई समाधान नहीं मिला। मैं क्या गलत कर रहा हूं? ऐसा लगता है कि PHP PHP अनुरोध का जवाब नहीं दे रहा है। मैंने php-file को किसी भिन्न डोमेन पर ले जाने का प्रयास किया है, लेकिन परिणाम वही है, यह मेरे ब्राउज़र में काम करता है लेकिन संकलित ऐप में नहीं।
यहाँ jQuery कोड है कि ajax-कोड की शुरुआत करता है:
function get_rss_feed() {
//clear the content in the div for the next feed.
$("#feed_content").empty().html('<img class="loader" src="js/images/ajax-loader.gif" alt=""/>');
$.ajax({
url: 'http://192.168.1.7/rssApp/www/rss-proxy.php?url=http://www.nytimes.com/services/xml/rss/nyt/GlobalHome.xml',
success: function parseRSS(d) {
//find each 'item' in the file and parse it
$(d).find('item').each(function() {
//name the current found item this for this particular loop run
var $item = $(this);
// grab the post title
var title = $item.find('title').text();
// grab the post's URL
var link = $item.find('link').text();
// next, the description
var description = $item.find('description').text();
//don't forget the pubdate
var pubDate = $item.find('pubDate').text();
// now create a var 'html' to store the markup we're using to output the feed to the browser window
var html = "<div class=\"entry\"><h2 class=\"postTitle\">" + title + "<\/h2>";
html += "<em class=\"date\">" + pubDate + "</em>";
html += "<p class=\"description\">" + description + "</p>";
html += "<a href=\"" + link + "\" target=\"_blank\">Read More >><\/a><\/div>";
//put that feed content on the screen!
$('#feed_content').append($(html));
});
$('#feed_content img.loader').fadeOut();
}
});
};
यहाँ आरएसएस-proxy.php कि यूआरएल और आउटपुट से XML लोड करता है यह:
<?php
// PHP Proxy
// Loads a XML from any location. Used with Flash/Flex apps to bypass security restrictions
// Author: Paulo Fierro
// January 29, 2006
// usage: proxy.php?url=http://mysite.com/myxml.xml
$session = curl_init($_GET['url']); // Open the Curl session
curl_setopt($session, CURLOPT_HEADER, false); // Don't return HTTP headers
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Do return the contents of the call
$xml = curl_exec($session); // Make the call
header("Content-Type: text/xml"); // Set the content type appropriately
echo $xml; // Spit out the xml
curl_close($session); // And close the session
?>
मैं कोड से उस आईपी पते को हटाने की सलाह दूंगा। – sciritai
क्या होता है जब आप सिम्युलेटर या डिवाइस पर ब्राउज़र से '.php' फ़ाइल खोलते हैं? क्या PHP निष्पादित हो जाता है? – Marko
टिप्पणियों के लिए धन्यवाद! मैंने सिम्युलेटर में ब्राउज़र से '.php' फ़ाइल तक पहुंचने का प्रयास किया है और यह काम करता है। लेकिन यह केवल तभी काम करता है जब मैं यूआरएल को सापेक्ष होने के लिए बदलता हूं, पूर्ण नहीं: 'url:' rss-proxy.php? Url = http: //www.nytimes.com/services/xml/rss/nyt/GlobalHome.xml ' '। यदि अब मैं अपने फोनगैप एप्लिकेशन के अपने www-folder में index.html फ़ाइल पर जाने के लिए मोबाइल सफारी ब्राउज़र का उपयोग करता हूं, जिसे मैं अपने 'htdocs' निर्देशिका में अपने स्थानीय एमएएमपी सर्वर पर होस्ट कर रहा हूं, यह काम करता है! लेकिन संकलित फोनगैप ऐप से नहीं। और निश्चित रूप से, '.php' फ़ाइल www- फ़ोल्डर में अन्य स्क्रिप्ट फ़ाइलों के साथ स्थित है। – user1029978