Jump to content


Photo

Help me with cross-domain ajax request (or JSONP)


  • Please log in to reply
1 reply to this topic

#1 mostafatalebi

mostafatalebi

    Advanced Member

  • Members
  • PipPipPip
  • 199 posts

Posted 21 September 2013 - 01:51 PM

Hello everybody

 

I don't know what should I do for cross-domain ajax request. Whatever I do does not work. For instance the following code just fails:

$.ajax({
    type : "GET",
    dataType : "jsonp",
    url : "myurl.com/file_to_process.php",
    data : "name=myName",
    success : function (msg)
    {
       console.log(msg);
     }
     error : function ()
     {
       console.log("ERROR");
     }
});

the server PHP file:

if(isset($_GET['name']))
{
    echo $_GET['callback'];
}

The above code always console.log "ERROR" and has made me mad. I have tried it with numerous tiny changes


Edited by mostafatalebi, 21 September 2013 - 01:57 PM.

Visual Effects Programming

Autodesk Maya, Autodesk Mudbox, Nvidia Mental Images Mental Ray, Adobe Photoshop, Adobe Illustrator, Adobe After Effects, CorelDraw

#2 ignace

ignace

    Now mod flavored

  • Moderators
  • 6,266 posts
  • LocationBelgium

Posted 21 September 2013 - 02:49 PM

The url has to be:

http://url.com/file_to_process.php




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com