开发者

Ajax post failing in asp

hey guys, this might be really stupid, but hopefully someone can help. I'm trying to post to an external script using ajax so i can mail the data, but for some reason my data is not making it to the script.

$(document).ready(function() {
$("#submitContactForm").click(function () {
    $('#loading').append('<img src="http://www.xxxxxxxx.com/demo/copyshop/images/loading.gif" alt="Currently Loading" id="loadingComment" />');
        var name = $('#name').val();
        var email = $('#email').val();
        var comment = $('#comment').val();
        var dataString = 'name='+ name + '&email=' + email + '&comment=' + comment;

        $.ajax({
            url: 'http://www.xxxxx.com/demo/copyshop/php/sendmail.php',
            type: 'POST',
            data: '?name=Dave&email=xxxxxxx@gmail.com&comment=hiiii',
            success: function(result) {
                $('#loading').append('success');
                }
            });    

    return false;
});
});

the php script is simple (for now - just wanted to make sure it worked)

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];

$to = 'xxxxx@xxxxx.com';
$subject = 'New Contact Inquiry';
$message = $comment;

mail($to, $subject, $message);
?>

the jquery is embedded in an .aspx page (a language i'm not familiar with) but is posting to a php script. i'm receiving emails properly but there i开发者_如何转开发s no data inside. am i missing something? i tried to bypass the variables in this example, but its still not working

thanks


You can't using Ajax to talk to a site that isn't in the same origin as the document your script is running in, unless both the browser and the destination support CORS. You can use JSONP to work around it a bit, but really CORS is the future in this regard.


You cannot use AJAX to send a request to a different domain.


Remove the '?' character from your data. I'm guessing this is messing up the data parsing in PHP.

When posting the data should be encoded using encodeURIComponent and this will encode ? as %3F.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜