2017-07-13 7 views
0

と後ろのコードでメソッドを呼び出すためにどのようにこれはこれは、背後にあるコードでスクリプトDotNetNukeのは、Ajax

<script type="text/jscript"> 
function ajaxcall(e) { 
    $.ajax({ 
     type: "POST", 
     url: "/DesktopModules/Modules/Admin/City/AddCity.ascx/GetMethod", 
     contentType: "application/json; charset=utf-8", 
     data: JSON.stringify({ value: "Vinay" }), 
     dataType: "json", 
     success: function (value) { 
      alert(value.d); 
     }, 
     error: function() { alert("Ajax Error"); } 
    }); 
}; 

です。それは私がAddCity.ascx/GetMethodによって/DesktopModules/Modules/Admin/City/AddCity.ascx/GetMethodを置き換える試みたが、それはまだ動作しませAjax Error

<input type="button" id="button" value="Test" onclick="ajaxcall()" /> 

警告JS見ます!

答えて

1

ASCMのusercontrolからWebMethodを呼び出すことはできません - IISは許可しません。 ASPXページにある必要があります。

セキュリティが不要な場合は、汎用ハンドラ(.ASHXファイル)を作成できます。

public class CityHandler : IHttpHandler 
{ 
    public void ProcessRequest(HttpContext context) 
    { 
     var fn = context.Request.QueryString["action"]; 
     var newCity = context.Request.QueryString["city"]; 

     if (fn == "add") 
     { 
      // TODO: add city 
     } 
     context.Response.ContentType = "text/plain"; 
     context.Response.Write("OK"); 
    } 

    public bool IsReusable 
    { 
     get { return false; } 
    } 
} 

次に、あなたのAjaxコードを変更:

$.ajax({ 
    type: "GET", 
    url: "/DesktopModules/Modules/Admin/City/CityHandler.ashx?action=add&city=Vinay", 
    success: function (value) { 
     alert(value); 
    }, 
    error: function() { alert("Ajax Error"); } 
}); 
+0

はあなたに感謝し、私はそれが私のために働くと思います。あなたの情報をありがとう。 –