user3488168 user3488168 - 1 month ago 9
Ajax Question

how to consume data from rest api using ajax jquery


i am new in j query ajax.i don't have idea how to fetch data from rest API using j query ajax. here i have created JS function to check whether passing URL working proper or not.
kindly help me.


<script type="text/JavaScript">
$.ajax({
type: "GET",
dataType: "jsonp",
url: "https://www.propertyfinder.ae/en/find-broker/ajax/search?page=1",
success: function(data){
alert(data);
}
});
</script>

Answer

You cannot do a cross domain call using ajax. what you can do is to do a php call like :

$website = file_get_contents('http://google.com');

and store it in a text file and access that using your ajax on your server using the same ajax file you have.

i had similar case that i had a php call on scheduler to grab text from url every minute and update a json file. then simply use :

$.getJSON( "ajax/test.json", function( data ) {
 //your function
});

or use ajax! whichever you fancy