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

时间:2022-11-23 17:37:18

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

2 个解决方案

#1


1  

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

将在您的服务器上提交的网址为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 =测试%20type&消息= Hellotesting

#2


1  

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
    }
});

#1


1  

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

将在您的服务器上提交的网址为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 =测试%20type&消息= Hellotesting

#2


1  

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
    }
});