json - How to show AJAX response message in alert? -


I am sending the user name and password as a request parameter to the server in AJAX and am trying to show the response message . But are not able to show response messages. This feedback message is showing in intelligence, but when the browser is not displaying it on the screen. Please help me with any help that I need to change where I am wrong or change anything. I wrote this way -

  $ (document) .ready (function () {$ ("# btnCity"). Click (function () {$ .ajax ({type: " POST ", url:" http://test.xyz.com/login ", CrossDamain: True, Content Type:" Application / Jason; Characterization = UTF-8 ", Data: {User Name:" ABC ", Password: "1234"}, Data Types: "JSONP", JasonPaybackback: 'Jason Callback', Async: Incorrect, Success: Function Warning (err.message);}});})}} {Warning (res.);} } {Warning (resdata);}, error: work (result, status, mistake) {warning (result.responseText);;  
< / Div>

TL; DR: I think the problem is in favor of the server your code (which we do not know yet First of all: I do not know why this is unsuccessful for you. I have taken your code and run it against the publicly available JSONP API, which is present in your system's current Returns to the IP and it works.

Please try yourself using the URL: http: // ip .jsontest.com / .

Therefore, the server does not return the correct response to the JSONP request. Take a look at the Networks tab in Developer Tools. With your current code, the server must respond to something like this:

  json callback ({'some response': 'someResponseValue'});  

Note: Content Type: App / Javascript in the header!


Should be BTW, even if it is not so - to solve your problem - here are some changes, I want to advise you:

  • async set to false on the documentation:

    Cross-domain requests and data types: "jsonp" requests do not support synchronous operation Are there.

  • You do not have to set a jsonpCallback , because jQuery generates and handle ( success Using the function will be random one for you. Excerpt from docs:

    This value will be used by jQuery instead of the randomly generated random name. This is a unique name for jQuery Better to generate because it manages the requests and the callback and error hand Gender is easy to provide.

  • So my code comes here:

      $ (document) .ready (function () { $ ("# BtnCity") .click (function () {$ .ajax ({type: "POST", url: "http://ip.jsontest.com/", crossdammon: true, data: {username: "Abc", password: "1234"}, datatype: "JSONP", success: function (resdata) {console.log ("success", reditata);}, error: function (result, status, fault) {console. Log ("error", result .comment text); Console.log ("error", status.responseText); Console.log ("error", err.Message); }}); }); });  

    One job.

    Another solution, such as the suggestion of the Yellow Iron, can be done with a predefined task and then explicitly set the jsonpCallback function that should be called .


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -