0

i am passing data to database using PHP - Ajax but i noticed if i use url:'xyz.php' hosted on my same server, where i placed other files related to project, then able to store data into database.

But when i use url:'http://www.domainname.com/myfolder/xyz.php' (using other server, not where i have placed project files) it doesnot store data to server ! WHY ?

here is my script which i used, please check and let me know how can i use complete instead of only file name like: xyz.php (using right now)

$.ajax({
        url:'xyz.php',
        data:$(this).serialize(),
        type:'POST',
        success:function(data){
            console.log(data);
        $("#success").show().fadeOut(5000);
        }

I hope my question is clear to all of you, just want to know how can i store data to server, if i am using complete URL in place of File name only

Garima
  • 9
  • 1
  • 6
  • 2
    http://en.wikipedia.org/wiki/Same-origin_policy – u_mulder Aug 20 '14 at 07:17
  • @u_mulder thanks for the link, but be frank friend not so clear to me, as i am new in development, will you help me to get my work done! In short what i have to do now ?? or is it not possible to use complete url and what would you recommend me to do --- to place this file in same server where i placed other files of same project – Garima Aug 20 '14 at 07:21
  • it's very difficult for me to understand, exactly what to do ?? – Garima Aug 20 '14 at 07:40
  • xyz.php should present in myfolder. Please place xyz.php file in same server where you placed other files of same project. – Naincy Aug 20 '14 at 11:21
  • Sorry @NaincyGupta I don't want to place xyz.php file in same server. Tell me another way if you know. – Garima Aug 20 '14 at 12:27

1 Answers1

0

By default, AJAX (XMLHttpRequest) cannot be sent to different domain. In order to overcome this, you have to use JSONP. There's a detailed guide of how to use it here: What is JSONP all about?

Community
  • 1
  • 1
Tania Petsouka
  • 1,388
  • 1
  • 9
  • 20