0

is it possible to call a page of another website from an ajax call ? my guess is that is possible since connection is not denied , but i can't figure out how to make my ajax call works , I am calling a list of TV Channels of a website , but I am getting no results , would you please see if my script contains any errors

function showValues(){
var myUrl="http://www.nilesat.com.eg/en/Home/ChannelList";
var all = 1;
$.ajax({
    url: myUrl+"&callback=?",
    data: "channelType="+all,
    type: 'POST',
    success: function(data) {
        $('#showdata').html(data);
    },
    error: function(e) {
        alert('Error: '+data);
    }  
});


} 


  showValues();

html div for results

<div id="showdata" name ="showdata">
</div>
salmanaacvf
  • 235
  • 7
  • 23

1 Answers1

0

Ajax calls are not valid across different domains.you can use JSONP. JQuery-ajax-cross-domain is a similar question that may give you some insight. Also, you need to ensure thatJSONP has to also be implemented in the domain that you are getting the data from.

Here is an example for jquery ajax(), but you may want to look into $.getJSON():

$.ajax({
    url: 'http://yourUrl?callback=?',
    dataType: 'jsonp',
    success: processJSON
});

Another option is CORS (Cross Origin Resource Sharing), however, this requires that the other server to enable CORS which most likely will not happen in this case.

You can try this :

    function showValues(){
    var myUrl="http://www.nilesat.com.eg/en/Home/ChannelList";
    var all = 1;

    $.ajax({
        url: myUrl,
        data: channelType="+all,
        type: 'POST',
        success: function (data) {
            //do something
        },
        error: function(e) {
            alert('Error: '+e);
        }  
    });

}
Partha
  • 402
  • 4
  • 15
  • it shows this error ReferenceError: $ is not defined , I have added that line – salmanaacvf May 31 '18 at 12:50
  • $ is not defined is a jquery error please check properly the if jquery library added properly or not – Partha Dec 25 '18 at 07:17