簡體   English   中英

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

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

我想在我的Word Press項目中使用帶有GET方法的Ajax提交表單。

我嘗試了兩種方法,但對我不起作用,我的代碼中有任何問題。

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

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

請幫忙

如果您想使用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
    }
});

你可以這樣

$.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 );
    },
});

將在您的服務器上提交的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