简体   繁体   English

jQuery ajax jsonp发布请求

[英]jquery ajax jsonp post request

I'm attempting to post form field results to a rest API located on another domain in the form of jsonp via ajax request. 我试图通过ajax请求将表单字段结果以jsonp形式发布到位于另一个域的rest API。 While this DOES work and the api receives the data I'm sending, chrome's network is showing this request as get rather than post, and chrome's console is firing the error function rather than success. 尽管此方法确实起作用,并且api接收到我正在发送的数据,但chrome的网络将此请求显示为get而不是post,而chrome的控制台正在触发错误功能而不是成功。

consider: 考虑:

-insert generic html form- -插入通用html表单-

$("form#email_signup").submit(function(e){
    e.preventDefault();

    var optionID = $('input[name=gender]:checked').val();
        emailID = $('#emailsignup').val();

    $.ajax({
    url: 'rest api',
    type: 'POST',
    data: {"type":"mergeListMembers","source":"signupForm","EMAIL_ADDRESS_":emailID, "GENDER":optionID, "EMAIL_PERMISSION_STATUS_":"I"},
    dataType: 'jsonp',
        success: function(){
          console.log('success!')
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            console.log('error!')
        }
    });
    alert('Thanks for signing up!');
});

Am I understanding this correctly? 我理解正确吗? Am I missing something? 我想念什么吗?

Thanks, Myles 谢谢,迈尔斯

Im pretty sure you cannot use POST in cross-domain . 我非常确定您不能在跨域中使用POST。 Change to GET 更改为GET

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM