After days of browsing on web and trying every possible thing, I came to know about there were issues with my host server. It was disabled by my host server. So, I thought o
Javascript Code for the client side
Part of the code required on the server side. You need to set the origin(referrers) who can ask for the page content, allow methods and headers. These settings can be stored either in the .htaccess file together for all the files on the 2nd domain to which you are making request, or, you can put them in your specific PHP file as shown:-
OR else , you can specify these settings for the entire domain/sub-domain together by mentioning the same in your .htaccess file as shown :-
Header set Access-Control-Allow-Origin: *
Header set Access-Control-Allow-Methods : POST,GET,OPTIONS,PUT,DELETE
Also not that the wildcard allowance to all the referrers can be sometimes unnecessary , so, in that case you can specify the specific domain/sub-domain by naming them , each of them separated by comma(,) as shown
Header set Access-Control-Allow-Origin: http://abc.com,http://def.com,http://ghi.com
Please comment in case you face some difficulty in implementing any of these. You can see live demo of what I mentioned here