Ajax Content Type: Application / Json Block Request

Here is my Ajax request:

  $ .ajax ({
       url: '',
       type: 'POST',
       data: JSON.stringify ({country: jcountry, region: jregion, from: jfrom, to: jto, currency: jcurrency}),
       processData: false,
       Content-Type: 'application / json',  
       dataType: 'json',
       success: function () {
       alert ("success")
       $ .mobile.changePage ("menu1.html");
       },
       error: function (xhr, ajaxOptions, thrownError) {
       alert ("Error:" + xhr.status + "\ n" +
              "Message:" + xhr.statusText + "\ n" +
              "Response:" + xhr.responseText + "\ n" + thrownError);
       $ .mobile.changePage ("menue2.html");
       }
       });

If I do not specify the type of content, I no longer see my request with firebug. Otherwise, when I add the content type, I can see the POST request (with an error because my URL is false), but in my header the content type is the default URL encoding.

I want to send information about my form via JSON data. Thanx for your help

0
source share
1 answer

You typed text contentType for content-Type

$.ajax({ url: '', type: 'POST', data: JSON.stringify({ country: jcountry, region: jregion, from: jfrom, to: jto, currency: jcurrency }), processData: false, ContentType: 'application/json', dataType: 'json', success: function () { alert("success") $.mobile.changePage("menu1.html"); }, error: function (xhr, ajaxOptions, thrownError) { alert("Error: " + xhr.status + "\n" + "Message: " + xhr.statusText + "\n" + "Response: " + xhr.responseText + "\n" + thrownError); $.mobile.changePage("menue2.html"); } }); 
0
source

Source: https://habr.com/ru/post/959041/


All Articles