Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Jquery+;冬眠+;Restfull web服务上的Maven?_Jquery_Ajax_Json_Hibernate_Maven - Fatal编程技术网

如何使用Jquery+;冬眠+;Restfull web服务上的Maven?

如何使用Jquery+;冬眠+;Restfull web服务上的Maven?,jquery,ajax,json,hibernate,maven,Jquery,Ajax,Json,Hibernate,Maven,我正在通过AJAX向基于Spring+Hibernate的应用程序发送JSON对象数据。当我使用高级chrome浏览器时,我可以发送,但通过JQuery无法发送。我使用的是硬编码的JSON数据 {“custName”:“Navin1”, “custMobile”:“876532468”, “电子邮件”:abc@gmal.com", “客户地址”:“巴纳奥雷” } 我在firefox控制台中收到以下消息。 跨源请求被阻止:同源策略不允许读取本地主机8080上的远程资源。这可以通过将资源移动到同一域

我正在通过AJAX向基于Spring+Hibernate的应用程序发送JSON对象数据。当我使用高级chrome浏览器时,我可以发送,但通过JQuery无法发送。我使用的是硬编码的JSON数据

{“custName”:“Navin1”, “custMobile”:“876532468”, “电子邮件”:abc@gmal.com", “客户地址”:“巴纳奥雷” }

我在firefox控制台中收到以下消息。 跨源请求被阻止:同源策略不允许读取本地主机8080上的远程资源。这可以通过将资源移动到同一域或启用CORS来解决。

<!DOCTYPE html>
<html lang="en">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
    $(document).ready(function(){
      $("button").click(function(){
        var custName = $('#custName').val();
        var custMobile = $('#custMobile').value;
        var custEmail = $('#custEmail').value;
        var custAddress = $('#custAddress').value;  

        var jsonData=JSON.stringify({
            "custName": "Navin1",
            "custMobile": "876532468",
            "custEmail": "abc@gmal.com",
            "custAddress": "BAnaore"
        });
        $.ajax({
                 url: "http://localhost:8080/HomeServiceProvider/customer/saveCustomer",
                 type: "POST",
                 dataType: "json",                  
                 data: jsonData,
                 contentType: "application/json",
             success: function(response){
                alert(JSON.stringify(response));
             },
             error: function(err){
                alert(JSON.stringify(err));
             }
        });

      });
    });
</script>
</head>
    <body>  
        <form>
            <fieldset style="text-align:right; width:300px">
                <legend><b>Registration Form</b></legend>
                Name <input type="text" id="custName" name="custName"/><br/>
                Mobile No <input type="text" id="custMobile" name="custMobile"/><br/>
                Email <input type="text" id="custEmail" name="custEmail"/><br/>
                Address <input type="text" id="custAddress" name="custAddress"/><br/>

                <button>Save Data</button>
            </fieldset>
        </form>                 
    </body>
</html>

$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
var custName=$('#custName').val();
var custMobile=$('#custMobile')。值;
var custEmail=$('#custEmail')。值;
var custAddress=$('#custAddress')。值;
var jsonData=JSON.stringify({
“客户名称”:“Navin1”,
“custMobile”:“876532468”,
“电子邮件”:abc@gmal.com",
“客户地址”:“巴纳奥雷”
});
$.ajax({
url:“http://localhost:8080/HomeServiceProvider/customer/saveCustomer",
类型:“POST”,
数据类型:“json”,
资料来源:jsonData,
contentType:“应用程序/json”,
成功:功能(响应){
警报(JSON.stringify(响应));
},
错误:函数(err){
警报(JSON.stringify(err));
}
});
});
});
登记表
名称
手机号码
电子邮件
地址
保存数据
您的答案在错误消息中

“可以通过将资源移动到同一域或启用CORS来修复此问题。”


看起来您是从loaclhost:8080加载页面的,但正在向192.168.1.12:8080发出请求请求请求的域需要与页面的域匹配。

您的问题是什么?你们做过网络搜索来理解那个错误的意思吗?谢谢你们的重播,但我只是在堆栈溢出中粘贴时删除了它。