How to pass value from javascript to php file

后端 未结 2 1310
我在风中等你
我在风中等你 2021-01-28 14:47

I am getting value via JQuery as something like this

var query= popURL.split(\'?\');  
var dim= query[1].split(\'&\'); 
var popWidth = dim[0].sp         


        
2条回答
  •  执念已碎
    2021-01-28 15:12

    well, if you only want to send that data to the server and you don't want to retrieve anything else and don't know or don't want to use ajax, a more simpler solution would be to attach the desired url on a hidden dom object. such as :

    witch can be added to the dom in multiple ways.

    If you want to use ajax, I recommend using a library such as jQuery, wich is optimized for cross-browser web apps. With jQuery, the syntax is very simple :

    $.get(
        "http://my-host.com/my-script.php",
        {"id" : id},
        function(data){
            // do something with the response
        }
    );
    
    You could use "post" instead of "get" depending on your needs. I recommend you take a peak at jQuery documentation.

提交回复
热议问题