Subhajyoti De
Subhajyoti De

Reputation: 47

jQuery AJAX sending link show broken

var dlink="http://www.example.com/downloadPkpass.php?temp=f5d022b2-8596-45e7-811d-611d42a15b6c&serial=100000000000135";
jQuery.ajax({
                type:"POST",
                url:'../sendMail.php',
                data: "date="+date+"&vname="+vname+"&offer="+offer+"&expiry="+expiry+"&dlink="+dlink,
                success:function(res)
                {

                },
            })

I used this snippet for my jQuery Ajax code.the problem is with the dlink variable. But in the sendMail.php page where I print the $_POST ,it is showing in a broken array not showing the original data. in sendMail.php it is showing like this:

[dlink] => http://www.example.com/downloadPkpass.php?temp=f5d022b2-8596-45e7-811d-611d42a15b6c [serial] => 100000000000135

Upvotes: 0

Views: 51

Answers (2)

Saty
Saty

Reputation: 22532

Wrong method to declare data

 data: "date="+date+"&vname="+vname+"&offer="+offer+"&expiry="+expiry+"&dlink="+dlink,

data is in the format of below:-

data: {date: date, vname: vname,offer: offer, expiry: expiry, dlink: dlink},

Upvotes: 0

jeroen
jeroen

Reputation: 91744

You need to encode your values correctly for use in a url. The easiest way is to have jQuery do that automatically by passing an object:

data: {'date': date, 'vname': vname, 'offer': offer, 'expiry': expiry, 'dlink': dlink},

You can also encode the value manually if you should want to (when you don't use jQuery for example):

var dlink=encodeURIComponent("http://www.example.com/downloadPkpass.php?temp=f5d022b2-8596-45e7-811d-611d42a15b6c&serial=100000000000135");

Upvotes: 2

Related Questions