Naveen
Naveen

Reputation: 125

How to send data to another server using jquery

I need to post data to another server using jquery.

Here is the code i am using

$.ajax({
    url:"https://www.thewiseagent.com:443/secure/webcontactAllFields.asp",
    type:'POST',
    data:"ID=" + $ID
        + "&Source=" + $Source
        + "&notifyCc=" + $notifyCc
        + "&notifyBcc=" + $notifyBcc
        + "&noMail=" + $noMail
        + "&CFirst=" + $first
        + "&CLast=" + $last
        + "&Phone=" + $Phone
        + "&Fax=" + $Fax
        + "&CEmail=" + $CEmail
        + "&Message=" + $message,
   success: function() {
       //window.location.href = "http://www.petlooza.com";
   }
});

i got error (302 object moved) in case of firefox/chorme although data is inserting.. but in case of IE data is not entering in external database. In IE i got a Access denied error.

Can anyone have alternative?

I have tried with json and jsonp still same error.

                           $.ajax({
                            type: "POST",
                            url: "https://www.thewiseagent.com:443/secure/webcontactAllFields.asp",
                            data: dataString,
                            dataType: "jsonp",
                            success: function(data) {
                            }

                            });                                        

Upvotes: 2

Views: 4196

Answers (3)

Raphael Petegrosso
Raphael Petegrosso

Reputation: 3870

You have a crossdomain problem. Try using jsonp:

$.ajax({
    url:"https://www.thewiseagent.com:443/secure/webcontactAllFields.asp",
    type:'POST',
    dataType: "jsonp",
    data:"ID="+$ID+"&Source="+$Source+"&notifyCc="+$notifyCc+"&notifyBcc="+$notifyBcc+"&noMail="+$noMail+"&CFirst="+$first+"&CLast="+$last+"&Phone="+$Phone+"&Fax="+$Fax+"&CEmail="+$CEmail+"&Message="+$message,
    success: function(data) {
        //window.location.href = "http://www.petlooza.com";
    }
});

Upvotes: 0

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76870

If you want to use $.ajax() and make a request to another domain you must set crossDomain option to true as stated in the documentation

$.ajax({
    url:"https://www.thewiseagent.com:443/secure/webcontactAllFields.asp",
    type:'POST',
    crossDomain: true,
    data:"ID="+$ID+"&Source="+$Source+"&notifyCc="+$notifyCc+"&notifyBcc="+$notifyBcc+"&noMail="+$noMail+"&CFirst="+$first+"&CLast="+$last+"&Phone="+$Phone+"&Fax="+$Fax+"&CEmail="+$CEmail+"&Message="+$message,
    success: function() {
        //window.location.href = "http://www.petlooza.com";
    }
});

Upvotes: 1

vascowhite
vascowhite

Reputation: 18440

You could make an AJAX request to a php script on your own server, which then gets the information from the other server and returns it to you jQuery. I can't think of any other way at the moment.

Upvotes: 0

Related Questions