无法使用其他项目中的jQuery调用Web服务 [英] Unable to call webservice using jquery from another project
问题描述
下午好!
我已经在新项目中创建了Web服务
返回Json数据的公共字符串GetProductsJson(字符串前缀)
我正在通过另一个项目使用这样的jquery来调用该Webservice
Hi Good Afternoon!
I have created webservice in new project
public string GetProductsJson(string prefix)which is returning Json data
and I am calling that webservice by using jquery like this from another project
$.ajax({
type: "POST",
url:"http://localhost:3904/Service1.asmx/GetProductsJson",
data: "{'prefix':'" + $(this).val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
crossDomain:true,
success: function(response) {
//getting data by using (response.d)
},
error: function(request, status, error) {
alert(request.responseText);
}
});
我使用了不同的网址
http://localhost:3904/Service1.asmx/GetProductsJson
http://localhost:3904/Service1.asmx?GetProductsJson
http://localhost:3904/Service1.asmx?op = GetProductsJson
但我没有得到任何回应.
如果我把Service&单个项目中的客户端代码即可正常工作.
请帮帮我..
-Dattatrya Moin
I have used different-different url
http://localhost:3904/Service1.asmx/GetProductsJson
http://localhost:3904/Service1.asmx?GetProductsJson
http://localhost:3904/Service1.asmx?op=GetProductsJson
but I am not getting any response.
If I put Service & Client code in single project then it works fine.
Please help me..
-Dattatrya Moin
推荐答案
.ajax({ 类型:" , url:" , 数据:" +
.ajax({ type: "POST", url:"http://localhost:3904/Service1.asmx/GetProductsJson", data: "{'prefix':'" +
(此).val()+ " , contentType:" , dataType:" , crossDomain: true , 成功:功能(响应){ // 使用(response.d)获取数据 }, 错误:功能(请求,状态,错误){ alert(request.responseText); } });
(this).val() + "'}", contentType: "application/json; charset=utf-8", dataType: "json", crossDomain:true, success: function(response) { //getting data by using (response.d) }, error: function(request, status, error) { alert(request.responseText); } });
我使用了不同的网址
http://localhost:3904/Service1.asmx/GetProductsJson
http://localhost:3904/Service1.asmx?GetProductsJson
http://localhost:3904/Service1.asmx?op = GetProductsJson
但我没有得到任何回应.
如果我把Service&单个项目中的客户端代码即可正常工作.
请帮帮我..
-Dattatrya Moin
I have used different-different url
http://localhost:3904/Service1.asmx/GetProductsJson
http://localhost:3904/Service1.asmx?GetProductsJson
http://localhost:3904/Service1.asmx?op=GetProductsJson
but I am not getting any response.
If I put Service & Client code in single project then it works fine.
Please help me..
-Dattatrya Moin
如果从另一个项目调用该Web服务,该Web服务是通过Visual Studio还是通过IIS运行?当它通过Visual Studio运行时,运行它的服务将分配一个唯一的端口(在这种情况下为3904),但是通过IIS,您需要删除该端口(因此:http://localhost/Service1.asmx?...)
快速测试:在VS中打开Web服务项目并启动它(在窗口右侧状态栏中的下面,您将收到一条消息,表明它正在运行)离开项目,然后打开包含JQuery项目的其他项目.运行它.
希望这会有所帮助.
If you call the webservice from another project is that webservice running via Visual Studio or via IIS? When it runs via visual studio the service that runs it will assign a unique port (3904 in this case), but through IIS you need to remove the port (thus: http://localhost/Service1.asmx?...)
A quick test: open the webservice project in VS and launch it (below in the status bar on the right in window you should get a message that it is running) Leave the project runnning and open your other project containing the JQuery project. Run it.
Hope this helps.
这篇关于无法使用其他项目中的jQuery调用Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!