简体   繁体   English

如何使用jquery和ajax在第三方url中使用get方法提交表单?

[英]How do i submit a form using get method in third party url using jquery and ajax?

I want to submit a form using ajax with GET method in my word press project. 我想在我的Word Press项目中使用带有GET方法的Ajax提交表单。

i tried two method but that not work for me there is any problem in my code. 我尝试了两种方法,但对我不起作用,我的代码中有任何问题。

Method-1 Using $.get 方法1:使用$ .get

$.get( "http://**.70.120.**/web/sms.aspx", { fullname: "John", contactnumber: "123333",Email_ID:"aniruddha@thinkbar.in",State:"MP",City:"Indore",Magma_Customer:"YES",Proposal_Number:"1234567890",Service_type:"CASE",Query_Type:"Test type",Message:"Hellotesting" } )
  .done(function( data ) {
    alert( "Data Loaded: " + data );
  })
  .fail(function( data ) {
    alert( "Data NOT Loaded: " + data );
     });

Method-2 using Ajax 方法2:使用Ajax

     $.ajax({
  method: "GET",
  url: "http://**.70.120.**/webleads/sms.aspx",
  data: {fullname: "John", contactnumber: "123333",Email_ID:"aniruddha@thinkbar.in",State:"MP",City:"Indore",Magma_Customer:"YES",Proposal_Number:"1234567890",Service_type:"CASE",Query_Type:"Test type",Message:"Hellotesting" }
})
  .done(function( msg ) {

    alert( "Data Saved: " + msg );
  }) 

  .fail(function( msg ) {

    alert( "Data NOT Saved: " + msg );
  })

Please help 请帮忙

if you want to do using ajax 如果您想使用ajax

$.ajax({
    data: { fullname: "John", contactnumber: "123333",Email_ID:"aniruddha@thinkbar.in",State:"MP",City:"Indore",Magma_Customer:"YES",Proposal_Number:"1234567890",Service_type:"CASE",Query_Type:"Test type",Message:"Hellotesting" },
    url: "http://**.70.120.**/web/sms.aspx",
    type: "GET",
    success: function(msg){
      //some function here
    }
});

You can do it like this 你可以这样

$.ajax({
    type: 'GET',
    url: 'http://**.70.120.**/webleads/sms.aspx',
    data: {
        'fullname': 'John', 
        'contactnumber': '123333',
        'Email_ID': 'aniruddha@thinkbar.in',
        'State': 'MP',
        'City': 'Indore',
        'Magma_Customer': 'YES',
        'Proposal_Number': '1234567890',
        'Service_type': 'CASE',
        'Query_Type': 'Test type',
        'Message': 'Hellotesting'
    },
    dataType: 'application/x-www-form-urlencoded',
    success: function(response) { 
        console.log( response );
    },
    error: function(errorThrown) {
        console.log( errorThrown );
    },
});

the url that will be submitted on your server will be http://**.70.120.**/webleads/sms.aspx/?fullname=John&contactnumber=123333&Email_ID=aniruddha@thinkbar.in&State=MP&City=Indore&Magma_Customer=YES&Proposal_Number=1234567890&Service_type=CASE&Query_Type=Test%20type&Message=Hellotesting 将在您的服务器上提交的url为http://**.70.120.**/webleads/sms.aspx/?fullname=John&contactnumber=123333&Email_ID=aniruddha@thinkbar.in&State=MP&City=Indore&Magma_Customer=YES&Proposal_Number=1234567890&Service_type=CASE&Query_Type=Test%20type&Message=Hellotesting

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM