c# - Connect javascript with asp.net -


I am having problems connecting JavaScript with ASP.NET Webform method via AJAX and Json.

For example, I have a folder and a page. Espacks have javascript - for example: - Account / CreateUser Apx - script / verb / creator JS

I have tried many things in the past, for example, the method [WebMath], many things change in Ajax action, but nothing works. Most of the sponsors give Google Chrome error:

POST ... / account / create user Apx / checkuuser name 401 (unauthorized)

If I delete them in JavaScript lines: "Data Type: Jason" and "Content Type: App / Jason; Charset = UTF-8" error disappeared And enters the "full" row ...

I need instructions to solve this problem ... I search for several posts, I follow several tutorials There is nothing else that means work. For example: Change my web configuration to accept any user, my root config ccs ...

What's going on? what? Do I need to declare something to use json?

Javascript:

  $ ("#USUserName") Change (function () (warning ($ ("(USUserName") .val ()); $ .ajax ({type: "post", url: "createUser.aspx / checkUserName", data: '{username: Content type: "Application / Jason; Charset = UTF-8", Datatype: "Jason", Complete: Function (Jessondata, State) {$ ("# USUSArame"). Val () + '' '}}, If (state == "success") {var response = JSON PRS (jsondata.responsetext) .d; warning ((response))}}, error: function (xhr, ajaxOptions, thrownError) {warning ();} });   

aspx cs code:

 [ScriptMethod (ResponseFormat = ResponseFormat.Json)] Public String CheckUserName (String Username) {var existUser = context.user.Where (us => (us.username) (value) (username)). Calculation (); string return value = string empty; if present user eclocks (0) {returnValue = "test-yes!";} And return value = "test-no!"; Return ReturnValue;}    

You need to use it to be able to call with WebMath AJAX Specialty for (if Omen is the same).

C #

  Public Partial Category PageName: Page {[WebMethod] Public Stabilized String MethodName () {Return "Success"; }}   

JS

  $ Ajax ({type: "POST", url: "PageName.aspx / MethodName", Data: "{}", ContentType: "Application / Jason; Charset = UTF-8", Data Type: "Jason", Success: Work (Msg) {// Something interesting is here.}} -   

Source:

If the domain is different, then you need to edit the cross domain policy:

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -