Ajax 客户端表单中的API调用返回404错误

Ajax 客户端表单中的API调用返回404错误,ajax,forms,mobile,Ajax,Forms,Mobile,我在客户机上有一个表单,用于调用api。如果我将api的url放在下面这样的表单操作中,它会起作用: 由于客户端是移动电话,上述解决方案不可行。但是,如果我将其放在ajax调用中,代码将返回404-Bad请求。我的ajax代码如下所示: $('#registration-form').on('submit',function(event) { // get the form data // there are many ways to get this data using jQ

我在客户机上有一个表单,用于调用api。如果我将api的url放在下面这样的表单操作中,它会起作用:

由于客户端是移动电话,上述解决方案不可行。但是,如果我将其放在ajax调用中,代码将返回404-Bad请求。我的ajax代码如下所示:

$('#registration-form').on('submit',function(event) {
    // get the form data
    // there are many ways to get this data using jQuery (you can use the class or id also)
    var formData = {
        'name'  : $('input[name=name]').val(),
        'email' : $('input[name=email]').val(),
        'password' : $('input[name=password]').val()
    };
    // process the form
    $.ajax({
        type : 'POST', // define the type of HTTP verb we want to use (POST for our form)
        url  : 'http://localhost:8080/thepostapi/v1/register', // the url where we want to POST
        data : JSON.stringify(formData), // our data object        
                    contentType: "application/json",
        dataType : 'json', // what type of data do we expect back from the server
                    success : function(response){ 
                        if(!response.error){ 
                            //Success
                            alert('data retrieved');
                        }else{ 
                            alert(response.message);
                        }
                    },
                    error :function (jqXhr, textStatus, errorThrown) {
                        alert("Error '" + jqXhr.status + "' (textStatus: '" + textStatus + "', errorThrown: '" + errorThrown + "')");

                    },
                    complete: function () {
                        $('#dvLoading').fadeOut(100);
                    }
    });
    event.preventDefault();
});

我在这里遗漏了什么吗???

404请求不错,资源找不到。检查localhost:8080是否已启动并可访问。这看起来像是跨域问题。浏览器将不允许调用请求来源域以外的域。@Subir Kumar Sao,那么API如何处理来自不同客户端的请求,因为如果客户端是移动设备,它肯定不会在同一个域上domain@TJ本地主机:8080正在运行,如果我使用Chrome的高级rest客户端扩展运行请求,结果将返回fine.JSONP,您还可以在服务器中设置CORS设置。标题集示例访问控制允许原点*