使用ajax向服务器发送请求

时间:2022-03-20 15:32:40

Hi i am trying to send request and want to hit my url on button click but it is not working

嗨,我正在尝试发送请求,并希望点击按钮点击我的网址,但它无法正常工作

updated code

    <script>
$(function(){

      $("#submit").click(function(){
var sms="url/sendmessage.php?user=""&password="&mobile=7828208357&message=hello&sender=&type=3INFORM";

    $.ajax({        
        url: sms ,
        data: "message=",
        type: 'POST',
        success: function (resp) {
            alert(resp);
        },
        error: function(e){
            alert('Error: '+e);
        }  
    });
      });

});
</script>

<input type="submit" value="submit" name="submit" id="submit">

Here given url i want to hit on button click How can i achieve this

给我的网址我想点击按钮点击我怎么能实现这一点

Any help will be appreciated

任何帮助将不胜感激

1 个解决方案

#1


0  

var sms="url/sendmessage.php?user=""&password="&mobile=7828208357&message=hello&sender=&type=3INFORM";

in this part of your code you should escape quotation marks like:

在你的代码的这一部分你应该转义引号,如:

var sms="url/sendmessage.php?user=\"\"&password=\"&mobile=7828208357&message=hello&sender=&type=3INFORM";

#1


0  

var sms="url/sendmessage.php?user=""&password="&mobile=7828208357&message=hello&sender=&type=3INFORM";

in this part of your code you should escape quotation marks like:

在你的代码的这一部分你应该转义引号,如:

var sms="url/sendmessage.php?user=\"\"&password=\"&mobile=7828208357&message=hello&sender=&type=3INFORM";